How to mount Windows share on Ubuntu Linux
CIFS (Common Internet File System) is a popular file sharing protocol on the Internet. It allows users on Linux systems to access specific installation points on Windows shares.
CIFS is an implementation of SMB (Server Message Block), which is a protocol used for network file sharing.
This tutorial will introduce all the steps to install and configure related utilities to mount Windows shares on Linux systems.
Install CIFS
Use the following command line to install the cifs-utils package on Ubuntu Linux
$ sudo apt-get update $ sudo apt-get install cifs-utils
Mount Windows Share
In this section, the tutorial will show you how to manually and automatically install Windows shares on Linux systems.
Create a directory on an Ubuntu Linux machine. The name of the directory is arbitrary. In the following command line, I created a folder named winshare under /mnt.
$ sudo mkdir /mnt/winshare
/mnt/winshare is the installation point of the remote Windows share.
You can use the cifs option of the mount command to mount the Windows share on the installation point of the Ubuntu Linux system
$ sudo mount -t cifs -o username=$windows_user,password=$windows_user_password //WIN_SHARE_IP/$shared_name /mnt/winshare
where:
WIN_SHARE_IP is the IP address of the Windows computer.
If $windows_user is in a Windows domain, specify the domain as the following command line
$ sudo mount -t cifs -o username=$windows_user,password=$windows_user_password,domain=$windows_domain_name //WIN_SHARE_IP/$shared_name /mnt/winshare
By default, Linux mounts Windows with full permissions (rwx or 777) to share. If you want to change the permissions yourself, use the dir_mode and file_mode options to set the permissions of the directories and files.
$ sudo mount -t cifs -o username=$windows_user,password=$windows_user_password,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/$shared_name /mnt/winshare
You can also change the default ownership of users and groups by specifying the uid (user ID) and gid (group ID) options.
$ sudo mount -t cifs -o username=$windows_user,password=$windows_user_password,uid=1000,gid=1000,dir_mode=0755,file_mode=0755 //WIN_SHARE_IP/$shared_name /mnt/winshare
After successfully installing the Windows share, use the command df -h to verify the installed Windows share in Linux. In the example below, WIN_SHARE_IP = 192.168.1.8 and $ shared_name = sharefolder
$ df -h Filesystem Size Used Avail Use% Mounted on udev 3,9G 0 3,9G 0% /dev tmpfs 787M 2,2M 785M 1% /run /dev/sda2 450G 23G 405G 6% / tmpfs 3,9G 705M 3,2G 18% /dev/shm tmpfs 5,0M 4,0K 5,0M 1% /run/lock tmpfs 3,9G 0 3,9G 0% /sys/fs/cgroup //192.168.1.8/sharefolder 300G 5,7G 295G 2% /mnt/winshare
Secure CIFS credentials
This section explains how to use the credential file when mounting a share using commands in Ubuntu Linux.
Create a CIF credential file: /etc/cifs-credentials. The file contains the following information:
username = $windows_user password = $windows_user_password domain = $windows_domain_name
Grant read and write permissions to the credential file:
$ sudo chmod +rw /etc/cifs-credentials
Now, we can install the share using credentials with commands as follows:
$ sudo mount -t cifs -o credentials=/etc/cifs-credentials //WIN_SHARE_IP/$shared_name /mnt/winshare
Automount share
If you use the mount command to manually mount the share, the share will be lost when you reboot the Linux computer.
The file /etc/fstab contains the necessary configuration that allows the CIF to be automatically and permanently mounted.
Edit the /etc/fstab file using your favorite editor (vim, nano, etc.)
$ sudo vim /etc/fstab
Then add the following lines to the file.
//WIN_SHARE_IP/$shared_name /mnt/winshare cifs credentials=/etc/cifs-credentials,file_mode=0755,dir_node=0755 0 0
Run command to mount all entries listed in /etc/fstab
$ sudo mount -a
From then on, the mounted CIF will remain unchanged after reboot.
Unload shares
In order to uninstall the share, you must determine the installation point. In the example above, the mount point is /mnt/winshare. Use the umount command:
$ sudo umount /mnt/winshare
If the mount point is busy and the above command fails, please run the command with option -l (–lazy)
$ sudo umount -t cifs -l /mnt/winshare
in conclusion
This tutorial has completed all the steps to use CIFS to install a Windows share on Ubuntu Linux. If you have any questions, please feel free to contact us.