LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Networking (https://www.linuxquestions.org/questions/linux-networking-3/)
-   -   Mounting Windows NT shared folders for individual users (https://www.linuxquestions.org/questions/linux-networking-3/mounting-windows-nt-shared-folders-for-individual-users-150482/)

Jake_da_Snake 02-25-2004 04:47 PM

Mounting Windows NT shared folders for individual users
 
I am using redhat 9.0 and suse 8.2. I am trying to mount windows NT shared folders on start up. I have four users. I used the following line on fstab.
//windowsNt/shared /linux/mount smbfs username=username,password=password 0 0
It works but it mounts the folders on start up for all users. I only want 2 of my users to be able to mount windows NT shared folders.
Is there a fstab file for individual users, or any other way to mount shared folders for specified users?\

jschiwal 02-25-2004 06:46 PM

I'm assuming that you want to allow 2 linux users to be able to access the samba NTFS share. Look up in man mount. There are options listed for smb mounts. The option that you want to add is gid=xxx. Make a new group for that purpose of sharing the NTFS share, and make those two users members of that group. You can enter the group name instead of the gid number in the fstab entry. Remember to make the new group before you add the gid= option.

Jake_da_Snake 02-26-2004 08:40 PM

Did that, and it didn't work. But it's a neat feauture though.
What I want to acheive is to mount NT shared folders for 2 users only. For instance I have four users. user1, user2, user3, and user4. I want the shared folders to be mounted when user1 and user2 log in, but I dont want it to be mounted when user3,4 log in.
What I thought I could do was to put them in .bash_profile or .bashrc of specific user, so they'd run everytime that user logged on. had no luck on that yet. I dont think that's possible anyway. A start-up file or something for individual users is pretty much what I had in mind.

rmanocha 02-26-2004 09:57 PM

well i dont think that putting the mount command in the user .bashrc file would not work....It should if you give it the right options like:
. mount -t smbfs .........

put this somewhere in your .bashrc and i think it should work.
bettre still you could put the entry in fstab and then just do a mount in .bashrc.
play around with it...i am sure this would work...oh only if i had a windows network to test this out....but i am much more happy without one...:)

rmanocha 02-26-2004 11:35 PM

yup...putting a script in .bashrc will work.i wrote this script:
Code:

#!/bin/bash
iam=`whoami`
if [ $iam = rmanocha ];then
        mount /dev/hda3 2>/dev/null
fi

and put in /etc/profile
and it works just fine...if the dev is already mounted then the error message will go to /dev/null else...it will mount this device.
I havent figured out how to umount it when i log out but i guess you can look into that.
hope this helped.

Jake_da_Snake 02-27-2004 11:19 PM

That looks like a great idea, but I'm bot very familiar with linux scripting, so if
you could be a little more specific, that would be great.

code:
#!/bin/bash
iam=`whoami`
if [ $iam = rmanocha ];then
mount /dev/hda3 2>/dev/null
fi


code:
#!/bin/bash:::: I suppose thiz 2 lines just should be there?

iam=`whoami` :::: I have no idea what this line does

[ $iam = rmanocha ] :::same goes for this line.

Assuming that I have 3 users. linuxuser1, linuxuser2 and linuxuser3. How would I mount
windows nt shared folders for linuxuser1?

eventhough I was trying to avoid fstab I put the following line in fstab just to see
what would happen.
//windowsNT/shared /shared smbfs username=username,password=password,noauto

then I used the .bashrc to mount that folder for linuxuser1

code:
#!/bin/bash
iam=`whoami`
if [ $iam = rmanocha ];then
mount /shared 2>/dev/null
fi
no luck
I couldn't even mount that from command prompt. I had to log on as root first.

Please Advice.
By the way I think u can unmount devices when u log out by using .bashlogout.

rmanocha 02-28-2004 02:12 AM

Quote:

Originally posted by Jake_da_Snake
code:
#!/bin/bash:::: I suppose thiz 2 lines just should be there?
This line has to be there since it is telling that bash will be used for interpreting this program(if you use other shells then you should look into those.

Quote:

iam=`whoami` :::: I have no idea what this line does
the whoami command basically tells you which user is running the current session...so like my user name under my linux box is rmanocha...so if i type whoami on the command line...i get back rmanocha.I store this value in a variable called iam.the "`" you see around the command is only to tell bash that you are supposed to execute this command.This is how i store who is using the current session into a variable..i could have probably used this in the if statement too but i am like that.:)

Quote:

if[ $iam = rmanocha ];then :::same goes for this line.
This line is basically like any other if statment in C/C++/JAVA etc.i am only checking who is the current user....my current user name is stored in iam and then i compare the value in i am with rmanocha(the user who should be able to mount the share).If this statement is true...that is if iam holds 'rmanocha' then go onto the next statement else just finish the program.

Quote:

Assuming that I have 3 users. linuxuser1, linuxuser2 and linuxuser3. How would I mount
windows nt shared folders for linuxuser1?
all you will have to do is write a if statement with something like this:
Code:

if [ $iam = linuxuser1 || $iam = linuxuser2 || $iam = linuxuser3 ];then
                        mount blah(put whatever it is you want to mount here) > /dev/null

Quote:

eventhough I was trying to avoid fstab I put the following line in fstab just to see
what would happen.
//windowsNT/shared /shared smbfs username=username,password=password,noauto
Even though i dont know much about samba(never really used it too much) i would say that maybe going with smbmount in the file we are writing could be a better solution.anyways...if the above fstab entry is correct...then there is still one problem you will run into.you are saying noauto...which means that this share will not be mounted automatically on boot(well to come to think of it...maybe you dont want to mount it when the machine boots...only when someone logs out...so i guess you can suit yourself). another thing you might want to add to this line is user so your fstab entry should look something like this:
Code:

//windowsNT/shared /shared smbfs username=username,password=password,noauto,user
This migh become easier if you actually look into the docs of smbmount and see if you can mount the shares using that program.

what you should have is this:
Code:

#!/bin/bash
iam=`whoami`
if [ $iam = linuxuser1 ];then
              mount /shared 2>/dev/null
fi

this should mount the shares just fine as described through fstab.the "2>/dev/null' is only to not display any error messages that this program may produce...since .bashrc is executed everytmie a shell will open hence the share might already be mounted when the user opens another shell and this will create a error message from mount.to get rid of that message you put it to /dev/null

hope this helps.let me know if it does.
a good site to learn bash programming is here


All times are GMT -5. The time now is 10:55 PM.