Professional Documents
Culture Documents
• Support
• Community
• Ubuntu.com
Ubuntu Wiki
Titles Text
Search: Search
• Immutable Page
• Info
• Attachments
More Actions:
•
• Ubuntu Wiki
• Login
• Help
MountWindowsSharesPermanently
Contents
This will help you mounting smbfs shares permanently. These can be shares on a Windows
computer or on a Linux/UNIX server running Samba.
15 oct. 2009: The libpam_mount section is no longer up to date with current releases. Can anyone
please update this section?
Is it true that smbfs is depricated? According to a blog post by Joey Stanford we need to use CIFS
instead of smbfs!
It appears to be true. I just fought through several strange problems after following this guide, only
to have everything solved by using CIFS instead.
I can confirm the above as well. I have changed "smbfs" to "cifs" where appropriate in this guide.
Then edit your /etc/fstab file (you need root privileges) to add this line:
//servername/sharename /media/mountname cifs
guest,uid=1000,iocharset=utf8,codepage=unicode,unicode 0 0
Where
• guest indicates you don't need a password to access the share,
• uid=1000 makes the Linux-user with specified uid or username owner of the mounted share,
thereby allowing that user to rename files,
• the combination iocharset=utf8,codepage=unicode,unicode allows access to files with
names in non-English languages. This doesn't work with shares of devices like the Buffalo
Tera Station, or Windows machines that export their shares using ISO8895-15. With these
the codepage argument has to be codepage=cp850, otherwise characters like the German
'Umlaute' are displayed as garbage.
After you added the entry to /etc/fstab type:
sudo mount -a
Place your username and password into the file. Replace the <REMOTEUSERNAME> and
<REMOTEPASSWORD> with the appropriate information:
username=<REMOTEUSERNAME>
password=<REMOTEPASSWORD>
Open the file system table file for editing. The following will use GEdit to edit it:
sudo gedit /etc/fstab
Add the remote share to the table on a line by itself. The following line when replaced with
appropriate data will mount the share for reading and writing:
//<SERVERNAME>/<REMOTEPATH> /<LOCALMOUNTPOINT>/<LOCALPATH> cifs
credentials=/home/<LOCALUSERNAME>/.smbcredentials,iocharset=utf8,file_mode=0777,
dir_mode=0777 0 0
Other Approaches
Assume the previous, plus:
• Share username on Windows computer is myusername.
• Share password on Windows computer is mypassword.
You could add the following to /etc/fstab:
//servername/sharename /media/mountname cifs
username=myusername,password=mypassword 0 0
However, the /etc/fstab is readable by everyone so it obviously wouldn't be a good idea to have your
Windows password in it. The way to get around this is by using what is known as a credentials file.
This is a file that contains just the username and password.
sudo gedit ~/.smbcredentials
Now add the following line in fstab for Read and write permission for everyone:
//servername/sharename /media/mountname cifs
credentials=~/.smbcredentials,dmask=777,fmask=777 0 0
(If the tilde "~" doesn't work in fstab, see the note below under Troubleshooting.)
or for only read permission:
//servername/sharename /media/mountname cifs credentials=~/.smbcredentials 0
0
then edit your /etc/rc.local to mount the smbfs when you log in (make sure the permissions on
your /etc/rc.local will allow users to execute it:
mount /media/mountname
exit 0
Special permissions
If you need special permission (like chmod etc.) you need to add uid or gid flag. You can set either
UID or username
//servername/sharename /media/mountname cifs
uid=uros,credentials=~/.smbcredentials,dmask=777,fmask=777 0 0
So for my user (craize) the User ID is 1000 and the Group ID is 1000 too.
Add the following to /etc/fstab:
//servername/sharename /media/mountname cifs
defaults,uid=1000,gid=1000,credentials=~/.smbpasswd,umask=777 0 0
(If the tilde "~" doesn't work in fstab, see the note below under Troubleshooting.)
Then edit the file /etc/security/pam_mount.conf using gedit or your preferred text editor (in
Kubuntu, the default is Kate). Since Ubuntu Hardy this file is named
/etc/security/pam_mount.conf.xml.
$ sudo gedit /etc/security/pam_mount.conf
NOTE: In 9.04 this entry does not exist in file /etc/security/pam_mount.conf.xml. Now what? Please
see my experimental setup (work in progress) below.
And add this line at the end of this session (bellow the provided examples):
volume username cifs servername sharename /home/&/mountname
uid=&,iocharset=utf8,fmask=0770,dmask=0770 - -
Where
• username is the user that, when logged, pam_mount will mount the volume. It is possible to
use * to all users or @groupname to all users that have groupname as their primary group
• cifs is the filesystem. It can be any of the filesystems listed on the session # Commands to
mount/unmount volumes, such as cifs (preferred) or "smbfs" (deprecated).
• servername can be the ip address or the assigned name (don't use // before them).
• sharename is the name of the share on the network folder. If the name of the share is your
username (like a home folder) you can use the & character.
• /home/&/mountname means /home/username/mountname. The & character means the
username in this file.
• uid=& makes the Linux-user with specified uid or username owner of the mounted share,
thereby allowing that user to rename files. You can specify a username instead of using the
& character
• fmask=0770,dmask=0770 will set rwx permissions on files and directories for the user and
the group specified with uid and gid.
Back up the pam gdm file:
$ sudo cp /etc/pam.d/gdm /etc/pam.d/gdm_backup
Then configure PAM to mount the external drive every time you login using gdm (change to kdm or
xdm if you use Kubuntu or Xubuntu).
$ echo "@include common-pammount" | sudo tee -a /etc/pam.d/gdm
Next time you reboot and login, the volume should be mounted without the need to enter your login
password twice or to write it down on a file.
Remove the comments (<!-- and -->) from the section called <luserconf
name=".pam_mount.conf.xml" />. Save the file when done. With this in place, users can create their
own ~/.pam_mount.conf.xml.
Next we'll create the ~/.pam_mount.conf.xml file for our example user 'joe'.
$ touch /home/joe/.pam_mount.conf.xml
Edit your freshly created config file and add the following:
<?xml version="1.0" encoding="utf-8" ?>
<pam_mount>
</pam_mount>
(If the tilde "~" doesn't work, see the note below under Troubleshooting.)
Still to 'translate' into XML format:
uid=&,iocharset=utf8,fmask=0770,dmask=0770 - -
[TBC]
I have tested it on 9.10.
Just added to /etc/security/pam_mount.conf.xml the following:
<volume options="uid=%(USER),gid=100,dmask=0700" user="*" mountpoint="/home/%
(USER)/mountname" path="sharename" server="servername" fstype="cifs" />
Troubleshooting
Unprotected network folder won't automount
I've had a situation where an unprotected network folder wouldn't automount during bootup, but
after manually entering "sudo mount -a" was mounted correctly. I solved this by replacing the
"guest" option by "username=guest,password=". If anyone has an explanation for this, please leave
a comment.
//servername/sharename /media/mountname smbfs
username=guest,password=,uid=1000,iocharset=utf8,codepage=unicode,unicode 0 0
CategoryDocumentation
The material on this wiki is available under a free license, see Copyright / License for details.