How to Mount SMB/CIFS network share in Linux

If you have a Home NAS and if it supports SMB/CIFS shares, then follow the steps below to mount those shares in a Linux System.

Prerequisite   Linux system must have “smbfs” and cifs-utils package installed.

Mount CIFS with the default local filesystem permissions:
# mkdir /mnt/mntpoint 
# mount -t cifs //server-name/share-name /mnt/mntpoint -o username=shareuser,password=sharepassword
 
For Example
 # mount -t cifs //192.168.1.2/myfolder /mnt/mntpoint -o username=shareuser,password=sharepassword
Where,
  • username=shareuser : specifies the CIFS user name.
  • password=sharepassword : specifies the CIFS password. If this option is not given then the environment variable PASSWD is used. If the password is not specified directly or indirectly via an argument to mount, mount will prompt for a password, unless the guest option is specified.
For further details and options, please read linux man page for mount.cifs(8). Also, please note that only root user can mount the filesystems.
If you want a particular filesystem to mounted at boot time, then enter a static information about the filesystem you want to mount in /etc/fstab.
For example, in /etc/fstab you need to enter 6 fields
“file system to be mounted”   “mount point”  “file type”  “options”  ” dump option” “file system check (fsck) value”
//192.168.1.2/myfolder  /mnt/mntpoint cifs  username=shareuser,password=sharepassword 0 0
if you want any user to mount this file system then do the following
//192.168.1.2/myfolder  /mnt/mntpoint cifs  username=shareuser,password=sharepassword,user 0 0
if you want to provide a resolvable hostname instead of IP address, then ensure that you have cifs-utils is installed. Otherwise you will fail to mount with error code -22 . If you do a dmesg after failure you will see the below message
cifs_mount failed w/return code = -22
Share: