Site icon DesignLinux

How to Mount Windows Share on Linux using CIFS

How to Mount Windows Share on Linux using CIFS

On Linux or UNIX OS, you can mount a Windows share on a specific point in the local directory tree using mount command with the cifs option. The Common Internet File System (CIFS) is a network file-sharing protocol. CIFS is a form of SMB. This tutorial explains how to mount Windows share on Linux systems.

Install CIFS Packages

You need to install the CIFS utilities package to mount a Windows share on a Linux systems.

Install CIFS utilities on Ubuntu and Debian:

sudo apt update
sudo apt install cifs-utils

Installing CIFS utilities on CentOS and Fedora:

sudo dnf install cifs-utils

For different Linux distributions, the package name might be differ.

Mount a CIFS Windows Share

It is a simple to mount the remote Windows share.

First of all, you should create a directory to serve as the mount point for the remote Windows share:

sudo mkdir /mnt/Windows_Share

After that, run the below command to mount the share as root or user with sudo privileges:

sudo mount -t cifs -o username= //WIN_SHARE_IP/ /mnt/WIN_SHARE

It will ask to enter the password:

Password:

On success authentication, it will not show any output.

You can verify using the mount or df -h command that Windows share is mounted properly.

Auto Mounting

If you mounted share manually using mount command, 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 following line to it:

# <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 mount command, will read the content of the /etc/fstab and mount the share.

Now once you reboot the system, the Windows share will be mounted automatically.

Unmounting Windows Share

You can detaches the mounted file system from the directory tree using the umount command:

sudo umount /mnt/WIN_SHARE

Check the fstab file that if the CIFS mount has an entry and remove it.

Make sure the umount command will failed to detach when the share is in use. Use the fuser command to find out which processes are accessing the windows share:

fuser -m MOUNT_POINT

After finding the processes, you can stop those using the kill command and umount the share.

Even if the umount failed, you can use the -l (--lazy) option to umount busy file system:

sudo umount -l MOUNT_POINT

Conclusion

This guide shows you how to mount a Windows shared using the mount command with the cifs option.

If you have any questions or feedback, please leave a comment below.

Exit mobile version