YouTube Icon

Code Playground.

How to Mount Windows Share on Linux using CIFS


How to Mount Windows Share on Linux using CIFS

On Linux and UNIX working frameworks, a Windows offer can be mounted on a specific mount point in the neighborhood registry tree utilizing the cifs choice of the mount order. 

The Common Internet File System (CIFS) is an organization document sharing convention. CIFS is a type of SMB. 

In this instructional exercise, we will disclose how to physically and naturally mount Windows shares on Linux frameworks. 

Installing CIFS Utilities Packages

To mount a Windows share on a Linux framework, first you have to introduce the CIFS utilities bundle. 

Introducing CIFS utilities on Ubuntu and Debian: 

sudo apt update
sudo apt install cifs-utils

Introducing CIFS utilities on CentOS and Fedora: 

sudo dnf install cifs-utils

The bundle name may vary between Linux dispersions. 

Mounting a CIFS Windows Share

Mounting a distant Windows share is like mounting customary record frameworks. 

To begin with, make a registry to fill in as the mount point for the far off Windows share: 

sudo mkdir /mnt/win_share

Run the accompanying order as root or client with sudo benefits to mount the offer: 

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

You will be incited to enter the secret phrase: 


On progress, no yield is delivered. 

To check that the distant Windows share is effectively mounted, use either the mount or df - h order. 

When the offer is mounted, the mount point turns into the root registry of the mounted record framework. You can work with the far off records as though they were neighborhood documents. 

The secret word can likewise be given on the order line: 

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

On the off chance that the client is in windows workgroup or area you can set it as follows: 

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

For better security it is prescribed to utilize an accreditations record, which contains the offer username, secret word and space. 

The accreditations record has the accompanying arrangement: 


username = user
password = password
domain = domain

The record must not be comprehensible by clients. To set the right consents and proprietorship , run: 

sudo chown root: /etc/win-credentials
sudo chmod 600 /etc/win-credentials

To utilize the accreditations record, characterize it as follows: 

sudo mount -t cifs -o credentials=/etc/win-credentials //WIN_SHARE_IP/<share_name> /mnt/win_share

Naturally of the mounted offer is possessed by root, and the consents are set to 777. 

Utilize the dir_mode alternative to set the index consent and file_mode to set the record authorization: 

sudo mount -t cifs -o credentials=/etc/win-credentials,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/<share_name> /mnt/win_share

The default client and gathering possession can be changed with the uid and gid choices: 

sudo mount -t cifs -o credentials=/etc/win-credentials,uid=1000,gid=1000,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/<share_name> /mnt/win_share

To set extra choices , include them as a comma-isolated rundown after the - o alternative. To get a rundown of all mount alternatives type man mount in your terminal. 

Auto Mounting

At the point when the offer is physically mounted with the mount order, it doesn't continue after a reboot. 

The/and so on/fstab record contains a rundown of sections that characterize where how and what filesystem will be mounted on framework startup. 

To naturally mount a Windows share when your Linux framework fires up, characterize the mount in the/and so on/fstab document. The line must incorporate the hostname or the IP address of the Windows PC, the offer name, and the mount point on the neighborhood machine. 

Open the/and so on/fstab record with your content manager : 

sudo nano /etc/fstab

Add the accompanying line to the document: 


# <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 accompanying order to mount the offer: 

sudo mount /mnt/win_share

The mount order, will peruse the substance of the/and so on/fstab and mount the offer. 

Next time you reboot the framework, the Windows offer will be mounted naturally. 

Unmounting Windows Share

The umount order disengages (unmounts) the mounted document framework from the registry tree. 

To withdraw a mounted Windows share, utilize the umount order followed by either the index where it has been mounted or far off offer: 

sudo umount /mnt/win_share

On the off chance that the CIFS mount has a passage in the fstab record, eliminate it. 

The umount order will neglect to segregate the offer when it is being used. To discover which cycles are getting to the windows share, utilize the fuser order: 

fuser -m MOUNT_POINT

When you discover the cycles, you can stop them with the execute order and unmount the offer. 

In the event that you actually have issues unmounting the offer, utilize the - l (- - apathetic) alternative, which permits you to unmount a bustling document framework when it isn't occupied any longer. 

sudo umount -l MOUNT_POINT


In Linux, you can mount a Windows shared utilizing the mount order with the cifs choice. 

On the off chance that you have any inquiries or criticism, don't hesitate to leave a remark.