[email protected]Office hours: Mon – Fri 9:00AM – 5:00PMLinkedInXFacebook
NexonHost
Netherlands Dedicated ServersAmsterdam · Equinix AM6Germany Dedicated ServersFrankfurt · Equinix FR4Romania Dedicated ServersBucharest · VoxilityAustria Dedicated ServersVienna · Interxion VIEBulgaria Dedicated ServersSofia · TelepointFrance Dedicated ServersParis · Interxion PAR — Marseille · Digital Realty MRS3Ireland Dedicated ServersDublin · Equinix DB2Italy Dedicated ServersMilan · Irideos AvalonPoland Dedicated ServersWarsawSpain Dedicated ServersMadrid · Equinix MD2United States Dedicated ServersAshburn · Equinix DC
All articles
Getting startedMarch 10, 2023

How to Mount Windows Share on Linux using CIFS

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:

    sudo apt updatesudo apt install cifs-utils
  • Installing CIFS utilities on CentOS and Fedora:

    sudo dnf install cifs-utils

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:

sudo mkdir /mnt/win_share

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

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

You will be prompted to enter the password:

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:

sudo mount -t cifs -o username=<win_share_user>,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 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 recommended to use a credentials file, which contains the share username, password and domain.

The credentials file has the following format:

 
username=user
password=password
domain=domain

The file must not be readable by users. To set the correct permissions and ownership , run:

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

To use the credentials file, define it as follows:

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

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:

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 user and group ownership can be changed with the uid and gid options:

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 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.

 

Auto Mounting

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 :

sudo nano /etc/fstab

Add the following line to 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 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:

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 in use. To find out which processes are accessing the windows share, use the fuser command:

fuser -m MOUNT_POINT

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.

sudo umount -l MOUNT_POINT

 

Conclusion

In Linux, you can mount a Windows shared using the mount command with the cifs option.

Keep reading
How to Implement Network Segmentation and Resource Isolation in Linux.
February 6, 2024

How to Implement Network Segmentation and Resource Isolation in Linux.

How to Implement Network Segmentation and Resource Isolation in Linux. Securing and managing networks in a Linux environment involves advanced practices like network segmentation and resource isolation. This guide explores these concepts, providing detailed instructions and examples for…

Read article
How to open or close ports in Linux.
February 6, 2024

How to open or close ports in Linux.

How to open or close ports in Linux. Effectively managing ports on your Linux system is crucial for both security and service accessibility. This comprehensive guide will provide a detailed walkthrough on opening and closing ports using the robust tools iptables and ufw. Understanding these…

Read article
How to use ypdomainname command.
January 23, 2024

How to use ypdomainname command.

How to use ypdomainname command. In the realm of Linux networking, the ypdomainname command plays a crucial role in the context of the Network Information Service (NIS). NIS, formerly known as Yellow Pages, is a distributed database service that facilitates the sharing of network configuration and…

Read article
Get in Touch

Together, Let’s Build a Faster, Safer Internet.

Build scalable infrastructure with NexonHost — high-performance dedicated servers, VPS hosting, colocation, and DDoS protection across Europe.

Get Started →Contact Us
[email protected]Office hours: Mon – Fri 9:00AM – 5:00PM