Learn How to Mount Windows Share on Linux using CIFS

Learn How to Mount Windows Share on Linux using CIFS

In this article we are going to shows how to Mount Windows Share on Linux using CIFS.

In Linux operating system, a Windows share can be mounted on a specific mount point in the local directory tree using mount command with the cifs option. The CIFS stands for Common Internet File System that is a network file-sharing protocol. CIFS is a form of SMB.


Install CIFS Packages

To mount a Windows share, firstly you need to install the CIFS utilities package in your Linux system:

Install CIFS utilities on Ubuntu and Debian:

Run the commands below to Install CIFS utilities on Ubuntu and Debian:

sudo apt update
sudo apt install cifs-utils

Install CIFS utilities on CentOS and Fedora:

sudo dnf install cifs-utils

Mount a CIFS Windows Share

To mounting a remote Windows share, First create a directory to serve as the mount point for the remote Windows share:

sudo mkdir /mnt/win_share

Run the command below as root or user with sudo privileges to mount the Windows share:

sudo mount -t cifs -o username=<win_share_username> //WIN_SHARE_IP/<share_name> /mnt/win_share

The above command will prompted to enter the password:

Output
Password:

To check that the remote Windows share is properly mounted, you can use the mount or df -h command.

Once the Windows share is mounted successfully, 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:

sudo mount -t cifs -o username=<win_share_username>,password=<win_share_password> //WIN_SHARE_IP/<share_name> /mnt/win_share

If the user is in windows workgroup or domain you can set it as bellow:

sudo mount -t cifs -o username=<win_share_username>,domain=<win_domain> //WIN_SHARE_IP/<share_name> /mnt/win_share

Auto Mounting 

If you mounted Windows share manually using mount command then it will 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.

You should define the mount in the /etc/fstab file to mount a Windows share automatically on your Linux system start up. 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.

Edit the /etc/fstab file with your text editor :

sudo nano /etc/fstab

Now add the below line into the file:

 <file system>             <dir>          <type> <options>                                                   <dump>  <pass>
//WIN_SHARE_IP/share_name  /mnt/win_share  cifs  credentials=/etc/win-credentials,file_mode=0755,dir_mode=0755 0       0

Run the following command to mount the share:

sudo mount /mnt/win_share

The above command will read the content of the /etc/fstab and mount the share.

Next time when 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 share, run the umount command followed by either the directory where it has been mounted or remote share:

sudo umount /mnt/win_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 already in use. To check out that which processes are accessing the windows share, run the fuser command:

fuser -m MOUNT_POINT

After find the processes, you can stop them with the kill command and unmount the share.

If you are still have problem to unmounting the Windows share then use the -l (--lazy) option. This option allows you to unmount a busy file system as soon as it is not busy anymore.

sudo umount -l MOUNT_POINT

That’s all.

If you face any error and issue in above steps , please use comment box below to report.

If our tutorials helped you, please consider buying us a coffee. We appreciate your support!

Thank you for your support.

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top