Archive

How to Mount CIFS Share for Ubuntu

For Ubuntu:

First you will need to make sure that Samba is installed.

The basic terminal command is mount -t cifs -o username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share

If you get an error:

mount error(79): Can not access a needed shared library

Refer to the mount.cifs(8) manual page (e.g. man mount.cifs)

try: mount -t cifs -o iocharset=iso8859-a, username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share

or:mount -t cifs -o iocharset=utf8, username=USERNAME,password=PASSWD //192.168.1.88/shares /mnt/share

The quickest way to auto-mounting a password-protected share is to edit /etc/fstab (with root privileges), to add this line:

//servername/sharename  /media/windowsshare  cifs  username=msusername,password=mspassword,sec=ntlm  0  0

This is not a good idea however: /etc/fstab is readable by everyone and so is your Windows password in it. The way around this is to use a credentials file. This is a file that contains just the username and password.

Using a text editor, create a file for your remote servers logon credential:

 

gedit ~/.smbcredentials

Enter your Windows username and password in the file:

 

username=msusername
password=mspassword

Save the file, exit the editor.

Change the permissions of the file to prevent unwanted access to your credentials:

 

chmod 600 ~/.smbcredentials

Then edit your /etc/fstab file (with root privileges) to add this line (replacing the insecure line in the example above, if you added it):

 

//servername/sharename /media/windowsshare cifs credentials=/home/ubuntuusername/.smbcredentials,sec=ntlm 0 0 

Save the file, exit the editor.

Finally, test the fstab entry by issuing:

 

sudo mount -a

If there are no errors, you should test how it works after a reboot. Your remote share should mount automatically.

 

Special permissions

If you need special permission (like chmod etc.), you'll need to add a uid (short for 'user id') or gid (for 'group id') parameter to the share's mount options.

 

//servername/sharename  /media/windowsshare  cifs   uid=ubuntuuser,credentials=/home/ubuntuuser/.smbcredentials,sec=ntlm   0       0

 

Mount password protected shares using libpam_mount (Ubuntu 9.04)

In addition to the initial assumptions, we're assuming that

  • Your username and password are the same on the Ubuntu machine and on the network drive.

Install libpam-mount:

sudo apt-get install libpam-mount

Edit /etc/security/pam_mount.conf.xml using your preferred text editor.

 

gksudo gedit /etc/security/pam_mount.conf.xml

First, we're moving the user specific config bits to a file which users can actually edit themselves: remove the commenting tags (<!-- and -->) surrounding 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.

 

gedit ~/.pam_mount.conf.xml

Add the following:

 

<?xml version="1.0" encoding="utf-8" ?>

<pam_mount>

<volume options="uid=%(USER),gid=100,dmask=0700" user="*" mountpoint="/media/windowsshare" path="sharename" server="servername" fstype="cifs" />

</pam_mount>