The filesystem for samba is known as smbfs. Samba is a software that can be run on a unix platform which uses the TCP/IP protocol that is installed on the host server to interact with a Microsoft Windows client or server. You can access the shared folders of windows machines on a linux machine by mounting the windows share into a local directory. In this article, we will see how we can access a windows share using mount command and fstab entry.
fstab entry for windows share
The syntax for SMB mount entry in fstab file is as follows.
//server/sharename /mnt/mountpoint smbfs <options> 0 0
//server/sharename : This corresponds to the Windows 2003/NT/Samba share name
/mnt/mountpoint: This corresponds to the existing local directory where the samba share needs to be mounted.
smbfs : This refers to the filesystem for samba.
<options> : There are a variety of options that you can use for smb mounts. We can go through the important options that you need to know to setup fstab entry for smb mounts.
This specifies the username to connect as. If this is not given, then the environment variable USER (which may contain the username of the person using the client) is used.
This specifies the SMB password. If this option is not given then the environment variable PASSWD(which may contain the password of the person using the client) is used. If it cannot find password smbmount will prompt for a password.
Rather than giving username and password directly in fstab file, you can specify a file that contains a username and/or password. The format of the file is:
This sets the uid that will own all files on the mounted filesystem. It may be specified as either a username or a numeric uid.
This sets the gid that will own all files on the mounted filesystem. It may be specified as either a groupname or a numeric gid.
This sets the file mask. This determines the permissions that remote files have in the local filesystem. This is not a umask, but the actual permissions for the files. The default is based on the current umask.
This sets the directory mask. This determines the permissions that remote directories have in the local filesystem. This is not a umask, but the actual permissions for the directories. The default is based on the current umask.
This sets the charset used by the Linux side for codepage to charset translations (NLS). The argument should be the name of a charset, like iso8859-1.
Sample fstab entry for SMB mount
//my_serv/F_Drive /mnt/fdrive smbfs credentials=/etc/sambapassfile,uid=sam,gid=users 0 0
Where, the file /etc/sambapassfile contains entries like,
Mounting SMB share
The SMB share can be mounted as follows,
mount -t smbfs //my_serv/F_Drive /mnt/fdrive -o credentials=/etc/sambapassfile,uid=sam,gid=users