How To Mount Windows Share On Linux Using CIFS
In this tutorial, we will explain how to manually and automatically mount Windows shares on Linux systems.
The Common Internet File System (CIFS) is a network file-sharing protocol. CIFS is a form of SMB.
On Linux and UNIX operating systems, a Windows share can be mounted on a particular mount point in the local directory tree using the cifs option of the mount command.
Installing CIFS Utilities Packages
To mount a Windows share on a Linux system, first you need to install the CIFS utilities package.
Installing CIFS utilities on Ubuntu and Debian:
Installing CIFS utilities on CentOS and Fedora:
The package name may differ between Linux distributions.
Mounting a CIFS Windows Share
Mounting a remote Windows share is similar to mounting regular file systems.
First, create a directory to serve as the mount point for the remote Windows share:
Run the following command as root or user with sudo privileges to mount the share:
You will be prompted to enter the password:
On success, no output is produced.
To verify that the remote Windows share is successfully mounted, use either the mount or df -h command.
Once the share is mounted, the mount point becomes the root directory of the mounted file system. You can work with the remote files as if they were local files.
The password can also be provided on the command line:
If the user is in windows workgroup or domain you can set it as follows:
For better security it is recommended to use a credentials file, which contains the share username, password and domain.
The credentials file has the following format:
The file must not be readable by users. To set the correct permissions and ownership , run:
To use the credentials file, define it as follows:
By default of the mounted share is owned by root, and the permissions are set to 777.
Use the dir_mode option to set the directory permission and file_mode to set the file permission:
The default user and group ownership can be changed with the uid and gid options:
To set additional options , add them as a comma-separated list after the -o option. To get a list of all mount options type man mount in your terminal.
When the share is manually mounted with the mount command, it does not persist after a reboot.
The /etc/fstab file contains a list of entries that define where how and what filesystem will be mounted on system startup.
To automatically mount a Windows share when your Linux system starts up, define the mount in the /etc/fstab file. The line must include the hostname or the IP address of the Windows PC, the share name, and the mount point on the local machine.
Open the /etc/fstab file with your text editor :
Add the following line to the file:
Run the following command to mount the share:
The mount command, will read the content of the /etc/fstab and mount the share.
Next time you reboot the system, the Windows share will be mounted automatically.
Unmounting Windows Share
The umount command detaches (unmounts) the mounted file system from the directory tree.
To detach a mounted Windows share, use the umount command followed by either the directory where it has been mounted or remote share:
If the CIFS mount has an entry in the fstab file, remove it.
The umount command will fail to detach the share when it is in use. To find out which processes are accessing the windows share, use the fuser command:
Once you find the processes, you can stop them with the kill command and unmount the share.
If you still have problems unmounting the share, use the -l (–lazy) option, which allows you to unmount a busy file system as soon as it is not busy anymore.
In Linux, you can mount a Windows shared using the mount command with the cifs option.