How to mount Samba share under Linux

I have a West Digital MyBook box serving as a file server for my home LAN. I can locate and use its samba share under Nautilus sometimes, but for some unknown reason, the share doesn’t show up occasionally. I decided to mount it via /etc/fstab and put it into /media, so that I can directly access it on Gnome desktop.

First, install smbfs package, I prefer wajig as my package maintainer.

wajig install smbfs

Then put this line into /etc/fstab. I don’t use a password for MyBook samba share, and I indicate null password and username to it:

//192.168.1.100/PUBLIC /media/smb smbfs username="",password="" 0 0

I refer using IP address instead of the server name to avoid the trouble of finding the WINS. The empty quotes behind the username and password options are feeding the null information to smbfs, telling it authentication is needed.

However, this does have a problem: the mounted share does not provide read/write permission for normal users. And I later discovered: even smbfs package is not necessary because the de facto cifs will do the same job and has better features.

Then what is the difference between smbfs and cifs? I read this from Linux CIFS Client Guide:

1) configuration
Unlike smbfs and smbclient, configuration for the cifs vfs does not depend on smb.conf.

2) mount syntax:
mounting to older servers may require specifying two additional fields beyond those which smbfs required:

3) Default UID/GID/mode for remote files
The default mode can be overridden by mount options “file_mode” and “dir_mode”for these server types.

The most important difference is to override the default UID/GID mode. I guess this holds the key to the no-rw-permission problem for a share mounted using smbfs. So eventually I came to this entry in my /etc/fstab

//192.168.1.100/PUBLIC /media/smb cifs dir_mode=0777,file_mode=0777,workgroup=MSHOME,gid=smb,uid=tux,rw,username="",password="" 0 0

make sure you have created a smb group and added the current user to that group by doing

$ sudo addgroup smb
$ sudo adduser $USER smb

Alternatively, if you want to use a samba share without all the work, just use “Place” menu under Gnome, choose “Connect to a server”, then select “Windows share” from the “Server type” drop-down menu and input the necessary information.

But mounting a Samba share directly to file system has one advantage: many programs will be able to run and open those shared files as if they were located on a local drive. Using the connect to server mode does not have this advantage.

Reference: https://wiki.edubuntu.org/ComprehensiveSambaGuide

Leave a Reply

Your email address will not be published. Required fields are marked *