Configuring a CIFS share on Linux

What is CIFS?

CIFS stands for “Common Internet File System”. CIFS is based on the enhanced version of Microsoft’s Server Message Block (SMB) protocol for Internet and intranet file sharing.

In the following example, we will look at connecting s CentOS 8 Linux system to a Windows system. For this connection to work, you will need to open port 445 between the Linux server and the Windows server.

For information relating to opening ports refer to: Firewall Commands

Install CIFS Packages on Linux Server

The package "cifs-utils" will need to be installed on your Linux RHEL/CentOS system. The following command can be issued:

dnf install cifs-utils

# dnf install cifs-utils
Last metadata expiration check: 0:24:44 ago on Sun 13 Jun 2021 14:32:57 BST.
Dependencies resolved.
 Package                      Architecture      Version                      Repository         Size
 cifs-utils                   x86_64            6.8-3.el8                    baseos             96 k
Installing dependencies:
 avahi-libs                   x86_64            0.7-20.el8                   baseos             62 k
 cups-libs                    x86_64            1:2.2.6-38.el8               baseos            433 k
 keyutils                     x86_64            1.5.10-6.el8                 baseos             63 k
 libicu                       x86_64            60.3-2.el8_1                 baseos            8.8 M
 libwbclient                  x86_64            4.13.3-3.el8                 baseos            119 k
 samba-client-libs            x86_64            4.13.3-3.el8                 baseos            5.4 M
 samba-common                 noarch            4.13.3-3.el8                 baseos            218 k
 samba-common-libs            x86_64            4.13.3-3.el8                 baseos            171 k

Transaction Summary
Install  9 Packages

Total download size: 15 M
Installed size: 55 M

Any dependencies that are required will also be installed to your Linux system.

Create a secure password

To connect to the Windows system, we have to add our windows credentials into a secure area. In this example, I will use the "/root" home area. The credentials will be stored in a file called: ".smbcred".

# pwd

# ls -al .smbcred
-r--------. 1 root root 33 Jun 13 15:01 .smbcred

# cat .smbcred 


The .smbcred file is created and the permissions have been set to "read-only" by issuing the "chmod 400 .smbcred" command.

The connecting user is referenced by the line "username" and the password is stored on the line "password".

Add a mount point in the mount tbale

To automatically connect the "CIFS" share at system start, we will need to add an entry into the mount table "/etc/fstab". In the example below "MSEDGEWIN10" is the name of the windows system and "john" is the name of the share on the windows system.

Mount table entry:

//MSEDGEWIN10/john      /mnt    cifs  dir_mode=0755,uid=john,gid=1000,file_mode=0755,credentials=/root/.smbcred   0 0

Once you have added the above entry (amend to match your environment), you can issue the following mount command to connect to the windows server share:

mount -a

# mount -a

# df -h /mnt
Filesystem          Size  Used Avail Use% Mounted on
//MSEDGEWIN10/john   40G   18G   23G  44% /mnt

From the above output, we can see that our share has been mounted to the "/mnt" area on our Linux system. The "df -h /mnt" was used to verify the mount.

Now we should be able to navigate to the "/mnt" area and test our access to the windows system.

# cd /mnt
# ls -l
total 1
-rwxr-xr-x. 1 john john 36 Jun 13 15:19 Test_File.txt.txt

# cat Test_File.txt.txt 
I am a test file on a windows server
# echo "Hello" > test.txt

# ls -l
total 1
-rwxr-xr-x. 1 john john 36 Jun 13 15:19 Test_File.txt.txt
-rwxr-xr-x. 1 john john  6 Jun 13 16:04 test.txt

From the above, we can see that we can read the contents of file "Test_File.txt". As a further test, I created a test file called "test.txt".

Verify share on Windows

The next screen shot shows the share from the Windows side:

Linux - Windows CIFS Share View