Mounting shared directories on Ubuntu using /ect/fstab

Their are many use cases for mounting shares on Linux machines. In this help article we will take you through some of them and give you example /ect/fstab entries.

Assumptions

Throughout this article, we make the following assumptions:

  • The windows server is located at: 192.168.1.181
  • The windows share we are mounting is: /windowsShare1 and /windowsShare2
  • The windows user name is: Bob
  • The windows password is: mypassword
  • The NFS server is located at: 192.168.1.182
  • The NFS share we are mounting is: /NFSShare1 and /NFSShare2
  • The NFS user name is: bobby
  • The Linux user name is : robert
  • The Linux user ID is: 1001
  • The Linux group ID for the group 'robert' is: 1001
  • The Linux group ID for the group 'user' is: 100

Use Cases

  1. Home machine, share mounted under the users home directory
  2. Multi-user home machine, share mounted under /share, low security
  3. Multi-user machine, higher security

Home Machine, mounted under the users home directory

In this very common use case, our home user has a NAS box with a single share that he wants mounted under his home directory (/home/robert/share). The files should be owned by the linux user 'robert' and the files should belong to the 'robert' group. Files and directories should be set to 770 (owner/group read/write, no access by others)

In our /ect/fstab file, we add the following line for a Windows share:

//192.168.1.181/windowsShare1  /home/robert/share/  cifs  username=Bob,password=mypassword,iocharset=utf8,sec=ntlm,uid=1001,gid=1001,file_mode=0770,dir_mode=0770,noperm 0 0

The above line mounts the windows share //192.168.1.181/windowsShare1 to /home/robert/share/ using the CIFS protocol. The line gives the username and password on the SAMBA/Windows server that has the authority to access that share. The owner of the file (as far as the Linux machine is concerned) is set to uid 1001 (robert) and gid 1001 (robert). The file and directory modes are set to 0770, giving robert:robert full access, and denying other users/groups any access to those files.

In our /ect/fstab file, we add the following line for a NFS share:

//192.168.1.182:/NFSShare1  /home/robert/share/  nfs  username=bobby,password=mypassword,rw,hard,intr  0     0

This command mounts the NFS share "NFSShare1" from the server at 192.168.1.182 to the /home/robert/share directory. The filesystem used is NFS. The username and password are specified. The filesystem is mounted read/write. The connection type is set to hard and it may be interrupted.

While this is acceptable for a home setup, any user with access to the /ect/fstab file can see your username and password in plain text, making it a potentially risky setup, especially in any setting where access control is a serious issue.

Multi-user home machine, mounted under /share, low security

In this use case, our home user has a NAS box with two shares that he wants mounted under in a shared location (/share). The files should be owned by the linux user 'root' and the files should belong to the 'users' group. Files and directories should be set to 774 (owner/group read/write, read only access by others)

In our /ect/fstab file, we add the following two lines:

//192.168.1.181/windowsShare1  /share/1/  cifs  username=Bob,password=mypassword,iocharset=utf8,sec=ntlm,gid=100,file_mode=0774,dir_mode=0774,noperm 0 0

and

//192.168.1.181/windowsShare2  /share/2/  cifs  username=Bob,password=mypassword,iocharset=utf8,sec=ntlm,gid=100,file_mode=0774,dir_mode=0774,noperm 0 0

The above line mounts the windows share //192.168.1.181/windowsShare1 to /share/1/ using the CIFS protocol. The line gives the username and password on the SAMBA/Windows server that has the authority to access that share. The owner of the file (as far as the Linux machine is concerned) is not specified, so it defaults to being owned by root and the gid is set to 100 (users). The file and directory modes are set to 0774, giving root:users full access, and allowing other users/groups read only access to those files.

Multi-user machine, higher security

MountSAMBAshareFSTAB (last edited 2015-07-27 14:40:57 by 5g3-steven-7tv)