The World

[as I find it]

Mount Samba shares on a GNU/Linux machine

Update: I found that these instructions were incomplete; they do mount the share correctly, but they cause the system to hang for a few minutes during a shutdown or reboot, because networking gets stopped before the shares are unmounted. Please see this later post for instructions on how to get Samba shares unmounted at the appropriate time when the system is shutting down.

Today I found myself needing to mount a Samba share in Ubuntu because I have a Bazaar repository there, and Bazaar doesn’t understand file paths that begin with “smb://”. So, even though it’s no problem to browse a Samba share in Ubuntu’s desktop file manager, I couldn’t perform checkouts or commits. To fix this, I had to do the following:

(All commands are run as root)

1. Install the smbfs package:
apt-get install smbfs

2. Create a credentials file with my Samba username and password:
nano /root/.cifscredentials

# .cifscredentials
# username and password for mounting Samba shares
# Note: this shouldn't be necessary if you are mounting a publicly-accessible share
username=richard
password=noyoucanthaveitsorry

(Actually, I’m not sure if comments are allowed in a Samba credentials file; strip them out before making your own.)

3. Add the share locations and mount points to /etc/fstab:
nano /etc/fstab

# /etc/fstab
# add the following to the bottom of the file to mount a Samba share
//SERVER/SHARENAME /path/to/mount/point cifs auto,iocharset=utf8,uid=USER,gid=GROUP,credentials=/root/.cifscredentials,file_mode=0775,dir_mode=0775 0 0
# That's one long line! But it must be *all one line*

Naturally, you must replace SERVER, SHARENAME, and /path/to/mount/point with the appropriate values for your system. USER and GROUP can both be your username, if you are the only one that needs access to the mounted share. Otherwise, use an appropriate choice of user and group. The way this works is that anyone in the allowed USER and GROUP settings will be reading and writing the remote share as if they were the remote user with the credentials you defined in the .cifscredentials files. Don’t give any GROUP access if you don’t want them to have all the permissions of that remote user!

Please note that I have used the terminal-based text editor nano in these instructions. GNU Nano is a re-implementation of the PICO editor. Control-O saves a file, Control-X exits the program. Most Ubuntu HOWTOs have you edit system configuration files in gedit, which is fine if you like waiting for a GNOME window to open when you’re working at the command line and the risk of having a mouse touch your configuration files thrills you. If you prefer, you can replace “nano” with “gedit” in the commands above; the rest is the same.

Credit where credit is due: I tried a number of different instructions for mounting Samba shares before I found that the above method worked. The core of these instructions came from MattVanStone, who is obviously a terrific guy, because now I can checkout my Python code, and eating hot dogs is very, very right.

Advertisements

Written by whereofwecannotspeak

December 12, 2007 at 8:57 pm

%d bloggers like this: