Linux systems can easily connect to Windows shared folders or other SMB (Server Message Block) network shares using the SMB/CIFS protocol. This allows seamless file sharing between Linux and Windows machines on a network.

In this post we will see how we can mount SMB shares on Linux.


Mount SMB Share on Linux

On SLES the cifs-utils are installed already which we can use to finally mount SMB shares.

The first version of the SMB network protocol, SMB1 or CIFS, is an old and insecure protocol, which has been deprecated by its originator, Microsoft.

For security reasons, the mount command on SUSE Linux Enterprise Server will only mount SMB shares using newer protocol versions by default, namely SMB 2.1, SMB 3.0, or SMB 3.02.

However, this change only affects mount and mounting via /etc/fstab. SMB1 is still available by explicitly requiring it. Use the following: The smbclient tool or the Samba server software shipped with SUSE Linux Enterprise Server.

Source: https://documentation.suse.com/sles/15-SP6/html/SLES-all/cha-samba.html#sec-samba-client-old-server


SLES15-SP5-Testing01:/ # zypper search-packages cifs


To mount SMB shares we can use the mount -t cifs command as show below. This will just mount the share temporary and we also need to enter the password.

SLES15-SP5-Testing01:~ # mount -t cifs //matrix-VM02.matrixpost-lab.net/fileshare01 /smbshare01/ -o username=superuser@matrixpost-lab.net


In order to mount a share without entering the user name and password, we can create a smb.cred file as shown below. I will store the file in the root users home directory.

SLES15-SP5-Testing01:~ # vi smb.cred


username=<username>
password=<password>
domain=<domain>


Set the permissions to only allow the owner to access the file:

chown user_name ~/smb.cred
chmod 600 ~/smb.cred


We can now pass the credentials=file_name mount option to the mount utility or use it in the /etc/fstab file to mount the share without being prompted for the user name and password.

SLES15-SP5-Testing01:~ # mount -t cifs //matrix-VM02.matrixpost-lab.net/fileshare01 /smbshare01/ -o credentials=/root/smb.cred


In order to mount the SMB share also permanently when the system boots we can add the following line to the /etc/fstab file.

//matrix-VM02.matrixpost-lab.net/fileshare01 /smbshare01/ cifs credentials=/root/smb.cred  0 0


We can unmount the SMB share as usual by executing the umount command.

SLES15-SP5-Testing01:~ # umount /smbshare01

Mounting a Share with the multiuser Option

By mounting as share with the multiuser option regular users can then provide their user name and password to the current session’s kernel keyring using the cifscreds utility.

If the user accesses the content of the mounted share, the kernel uses the credentials from the kernel keyring instead of the one initially used to mount the share.

SLES15-SP5-Testing01:/ # mount -t cifs //matrix-VM02.matrixpost-lab.net/fileshare01 /smbshare01/ -o multiuser,credentials=/root/smb.cred


By adding it into the /etc/fstab.

//matrix-VM02.matrixpost-lab.net/fileshare01 /smbshare01/ cifs multiuser,credentials=/root/smb.cred  0 0


When I am now trying to access the SMB share with a different user than root, which have access to the smb.cred file, I will get a Permission denied as shown below.


The permissions for the SMB share are as shown below.


I will now use the cifscreds utility to provide the user name and password to the current session’s kernel keyring for the Windows (Active Directory) user marcus.rath@matrixpost-lab.net which had permissions assigned to access the SMB share.

# cifscreds add -u <username> -d <domain or hostname>
marcus@SLES15-SP5-Testing01:/smbshare01> cifscreds add -u marcus.rath -d matrixpost-lab.net


To verify if a share is mounted with the multiuser option we can just enter the mount command.

SLES15-SP5-Testing01:~ # mount


Source: https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/storage_administration_guide/mounting_an_smb_share#performing_a_multi-user_smb_mount

Links

Mounting an SMB Share
https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/7/html/storage_administration_guide/mounting_an_smb_share

Mount an SMB Share in Linux
https://www.linode.com/docs/guides/linux-mount-smb-share/

Configuring a Samba client with YaST
https://documentation.suse.com/sles/15-SP6/html/SLES-all/cha-samba.html#sec-samba-client-inst-yast