I have a server that has a number of CIFS shares that need to be accessed on a per-user basis. For example, I have a Music share which I have full access to, but my wife has read-only access.
When either myself or my wife log into our Ubuntu 11.04 laptop I would like these shares to be automatically mounted per user. Now I understand that if I mount as -t cifs
without specifying a user then it will use the USER
environment variable. However, I also need to specify a password, so how can I do that when each user has a different password?
I think my questions are:
- Is there a way for me to have a per-user /etc/fstab?
- If not, is there a way to specify that a mount is only applicable to a certain user?
- Also, the share password is always the same as the local password. Is there a way to specify that this password should just pass through from the client to server rather than having to specify it in a credentials file somewhere?
Or maybe I'm missing something and there's a completely different solution. Can anyone help?
There are probably several solutions possible; here's is how I would do it. (Disclaimer: untested!)
The mount.cifs command can read the username and password from the
USER
andPASSWD
environmental variables, but it can also read them from a "credentials" file, that you specify on the command line with the-o cred=/path/to/credentials/file
option.The credentials-file approach is IMHO simpler to implement.
Create a text file
$HOME/.Music.cred
to store the credentials; the file should have this format:Protect the
$HOME/.Music.cred
file; run this command in a terminal:Now you should be able to mount the CIFS share
//server/music
on directoryMyMusicFolder
using this command:You can enable each user to run this through passwordless sudo by adding a line to
/etc/sudoers
: (one line per user)If the command from step 3. worked correctly, you can make it automatic in several ways:
/etc/X11/Xsession.d/30mount-cifs-shares
so that it will work for any user.Alternatively, you can replace steps 3. and 4. above with the use of pam-mount:
install package libpam-mount
configure
/etc/security/pam_mount.conf.xml
with:References:
As a note to myself and to others, the reason libpam-mount was failing with:
was due to the fact that my wireless network had not yet started when libpam was attempting the mounts. To rectify this, I had to set the wireless connection as "Available to all users" in the wireless connection settings. This allows the connection to activate prior to a user logging in.
Once I had set that property, libpam-mount worked fine.