[mythtv-users] Off Topic: Auto mount samba shares

Rod Smith mythtv at rodsbooks.com
Thu Feb 22 21:49:42 UTC 2007


On Thursday 22 February 2007 15:30, Joacim J wrote:
> Hello,
>
> I am a bit off topic here but hopes for some ideas...
>
> I have a server and a client both running Fedora Core 6. The server have a
> number of samba shares and different users have different access (e.g. no
> access, read, read/write). Those shares I would like to have mounted
> automatically at login time (not via fstab) and this because the client are
> used by others in the family.
>
> User A
> Read access to //server/movies to be mounted as /home/UserA/movies
>
> User B
> Read/Write access to //server/movies to be mounted as /home/UserB/movies
> Read/Write access to //server/apps to be mounted as /home/UserB/apps
>
> How can I solve this?

There are several ways to do this. One is to create /etc/fstab entries, such 
as:

//server/movies  /home/UserB/movies   smbfs  
users,noauto,credentials=/etc/samba/credentials/UserB,uid=500,gid=100,fmask=0640     
0 0

(That's a single very long /etc/fstab line that's gotten split across three 
lines.) You might want to tweak this in various ways, such as changing the 
uid and gid numbers, changing the fmask value, using cifs instead of smbfs 
(each has its advantages and disadvantages), or removing "noauto" from the 
line (to have the share be mounted automatically at boot time). You'd need to 
create a file called /etc/samba/credentials/UserB, which would hold the 
user's Samba username and password:

username=UserB
password=foobar

This file should, of course, have restrictive permissions to keep anybody but 
the user in question (and root) from reading it. Once this is configured, the 
user can mount the share just by typing "mount ~/movies" 
or "mount /home/UserB/movies" -- or if you omit the "noauto" option, the 
share will mount automatically at boot time.

Another way to do this is to have the user type "smbmount //server/movies 
~/movies" to mount the share. The user will ordinarily have to type a 
password, although there are ways around this, some more awkward than others. 
One that works well in a script would be to pass the -o credentials=file 
option to smbmount, which points to a credentials file, as described earlier.

You could use either of these commands in a user's login script to mount the 
share automatically when the user logs in, and to a logout script to unmount 
the share when the user logs out. (A simple script could easily get confused 
by multiple login sessions, though.) Is there any particular reason you want 
to have the shares mounted and unmounted when the users log in and out rather 
than have them mounted when the system boots? The latter is likely to be 
simpler to configure, although it could cause problems if the server goes 
down frequently.

Yet a third option would be to use NFS instead of Samba, but if you're not 
already running NFS on the server, that's unlikely to offer much in the way 
of advantages. One NFS advantage is that it tends to recover a bit better if 
the server goes down and then comes back up again, in my experience.

-- 
Rod Smith
http://www.rodsbooks.com


More information about the mythtv-users mailing list