Mounting a Windows share on Linux is pretty straight forward. You need a Windows user that can access the shares, the name of the work group or domain, and the name of the share.
First, make sure you have mount.cifs
installed, then create a credentials file, and finally mount the share. You can also add the filesystem to /etc/fstab if you like.
Required Packages
The package countaining mount.cifs must be installed before you can mount the share. On CentOS and Debian based distributions, it is called cifs-utils. There is a good chance it is already installed, but it won’t hurt to try to install it anyway.
On Debian based distributions:
tyler@desktop:~$ sudo su -
root@desktop:~# apt install cifs-utils
On RHEL based distrubitions:
tyler@centos7 ~]$ sudo su -
root@centos7 ~]# yum install cifs-utils
Create a Credentials File
I prefer to create credentials files instead instead of providing my password as an argument or being prompted for it. Credentials files prevent putting your password in /etc/fstab on shared systems.
Create a file with your favorite text editor (I prefer vi) that looks something like this:
username=tyler
password=mypassword
domain=TG
Mount the Filesystem
To mount the filesystem, use mount.cifs:
root@centos7 ~]# mount.cifs //server/share /mnt/server -o credentials=/your/credentials/file,rw
Replace the highlighted sections with what is relevant. The UNC name //server/share is the same thing you would type into the address bar of Windows Explorer, except you use / instead of \.
The table below describes some options you may find useful. See the mount.cifs for a complete list of options.
Option | Description |
---|---|
uid=arg | Sets the owner of all files on the share to the UID specified. The default is 0. The server usually still treats everything you do as if it was done by the user you authenticated with when you mounted the filesystem. |
gid=arg | Sets the group of all files on the share to the GID specified. The default is 0. The server usually still treats everything you do as if it was done by the user you authenticated with when you mounted the filesystem. |
file_mode=arg | Sets the mode of all files on the share. As with the previous options, access control on the server side is still controlled by the user you logged into the server with. |
dir_mode=arg | Sets the mode of all directories on the share. As with the previous options, access control on the server side is still controlled by the user you logged into the server with. |
Add the Share to /etc/fstab
If you plan to add the share to /etc/fstab, here is an example:
//server/share /winserver cifs user,rw,credentials=/etc/cifs_credentials,noauto,uid=5000
The options are the same ones you would use on the command line along with the usual /etc/fstab options. I recommend using noauto or _netdev to ensure the system doesn't try to mount the share before the network is available.