A Windows share can be mounted on a specific mount point in the local directory tree using the cifs option of the mount
command on Linux and UNIX operating systems.
The Common Internet File System (CIFS) is a mechanism for exchanging files across a network. SMB is a kind of CIFS.
In this guide, we'll show you how to mount Windows shares on Linux computers both manually and automatically.
CIFS Utilities Packages Installation
You must first install the CIFS utilities package before mounting a Windows share on a Linux machine.
- CIFS utilities installation on Ubuntu and Debian:
sudo apt updatesudo apt install cifs-utils
- CIFS utilities installation on CentOS and Fedora:
sudo dnf install cifs-utils
The name of the package may vary depending on the Linux distribution.
Mounting a Windows CIFS Share
Mounting a remote Windows share works in the same way as mounting a standard file system.
Create a directory to act as the remote Windows share's mount point first:
sudo mkdir /mnt/win_share
To mount the share, run the following command as root or as a user with sudo privileges:
sudo mount -t cifs -o username=<win_share_user> //WIN_SHARE_IP/<share_name> /mnt/win_share
You will be asked to enter the following password:
Password:
There is no output when you succeed.
Use the mount or df-h
commands to check that the remote Windows share has been mounted successfully.
Once the share is mounted, the mount point becomes the mounted file system's root directory. You can work with distant files in the same way that you would with local ones.
The password can be specified on the command line as well:
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 a member of a Windows workgroup or domain, you can set it to:
sudo mount -t cifs -o username=<win_share_user>,domain=<win_domain> //WIN_SHARE_IP/<share_name> /mnt/win_share
A credentials file containing the share username, password, and domain is recommended for improved security.
This is the format of the credentials file:
/etc/win-credentials
username=user password=password domain=domain
Users should be unable to access the file. Run the following command to set proper rights and ownership:
sudo chown root: /etc/win-credentialssudo chmod 600 /etc/win-credentials
If you want to use the credentials file, set it up like this:
sudo mount -t cifs -o credentials=/etc/win-credentials //WIN_SHARE_IP/<share_name> /mnt/win_share
The mounted share is owned by root by default, with 777 rights.
Set directory permissions using dir_mode, and file permissions with file_mode:
sudo mount -t cifs -o credentials=/etc/win-credentials,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/<share_name> /mnt/win_share
The uid and gid parameters can be used to alter the default owner of a user or a group:
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
After the -o option, add any other options as a comma-separated list. In your terminal, run man mount to receive a list of all mount options.
Mounting on its own
When using the mount command to manually mount a share, it does not remain after a reboot.
The /etc/fstab file provides a series of entries that specify where and how the filesystem will be mounted when the system boots up.
Define a mount in the /etc/fstab file to automatically mount a Windows share when your Linux system boots up. The line must include the Windows PC's hostname or IP address, the share name, and the local machine's mount point.
With your text editor, open the /etc/fstab file.
sudo nano /etc/fstab
To the file, add the following line:
/etc/fstab
# <file system> <dir> <type> <options> <dump> <pass> //WIN_SHARE_IP/share_name /mnt/win_share...Read more »