Mount and unmount CIFS network file systems

First, we are going to install the cifs-utils and samba-client packages:

# yum install cifs-utils samba-client

We need to know what the server is sharing:

In this step, it is not necessary to enter a password to see what the server is sharing.

In the previous image, we can see that the ipa server is sharing the “data” directory (authentication required) and the “public” directory.

To login to the samba console as a guest:

[root@cliente1 yum.repos.d]# smbclient //servidoripa.example.com/public -U guest
 Enter guest's password:    <---(enter)
 Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
 smb: > ls
   .                                   D        0  Fri Jun  8 17:41:28 2018
   ..                                  D        0  Fri Jun  8 17:41:28 2018
     17811456 blocks of size 1024. 10501544 blocks available

To login to the samba console as a created user:

[root@cliente1 yum.repos.d]# smbclient //servidoripa.example.com/data -U sambauser1
 Enter sambauser1's password: 
 Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
 smb: > ls
   .                                   D        0  Fri Jun  8 17:41:28 2018
   ..                                  D        0  Fri Jun  8 17:41:28 2018
   samba-user-1                        N        0  Fri Jun  8 17:41:28 2018
   samba-user-2                        N        0  Fri Jun  8 17:41:28 2018
   samba-user-3                        N        0  Fri Jun  8 17:41:28 2018
     17811456 blocks of size 1024. 10493268 blocks available
 smb: > exit

To temporarily mount a samba fs (data directory):

[root@cliente1 mnt]# mount -t cifs -o username=sambauser1 //servidoripa.example.com/data /mnt/temp/
 Password for sambauser1@//servidoripa.example.com/data:  ********

 [root@cliente1 mnt]# ls -l /mnt/temp/
 total 0
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-1
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-2
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-3

To dismount:

[root@cliente1 mnt]#  umount temp/

To permanent mount a samba fs(public directory):

[root@cliente1 mnt]# echo "//servidoripa.example.com/public /mnt/perm/ cifs _netdev,guest 0 0 " >> /etc/fstab 

 [root@cliente1 mnt]# mount -a

 [root@cliente1 mnt]# df -h /mnt/perm/
 Filesystem                        Size  Used Avail Use% Mounted on
 //servidoripa.example.com/public   17G  7.0G   11G  42% /mnt/perm
 [root@cliente1 mnt]# 

To permanent mount a samba fs(data directory) – [Password required]:

[root@cliente1 perm]# echo "//servidoripa.example.com/data /mnt/perm/ cifs _netdev,username=sambauser1 0 0 " >> /etc/fstab 

[root@cliente1 perm]# mount -a
 Password for sambauser1@//servidoripa.example.com/data:  ******

 [root@cliente1 perm]# df -h /mnt/perm/
 Filesystem                      Size  Used Avail Use% Mounted on
 //servidoripa.example.com/data   17G  7.0G   11G  42% /mnt/perm

To permanent mount a samba fs(data directory) – [Verifying the credentials in a file.]:

We must create a file with the user names and passwords credentials:

[root@cliente1 ~]# cat > cred << EOF
   username=sambauser1
   password=password
   EOF
   [root@cliente1 ~]# cat cred 
   username=sambauser1
   password=password 

Change permissions for security:

[root@cliente1 ~]# chmod 400 cred 

[root@cliente1 ~]# ll cred 
 -r--------. 1 root root 38 May  9 07:22 cred

And send the entry to the fstab file:

[root@cliente1 ~]# echo "//servidoripa.example.com/data /mnt/perm/ cifs _netdev,credentials=/root/cred 0 0 " >> /etc/fstab
 
[root@cliente1 ~]# mount -a

[root@cliente1 perm]# df -h /mnt/perm/
 Filesystem                      Size  Used Avail Use% Mounted on
 //servidoripa.example.com/data   17G  7.0G   11G  42% /mnt/perm

 [root@cliente1 ~]# cd /mnt/perm/
 [root@cliente1 perm]# ll
 total 0
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-1
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-2
 -rw-r--r--. 1 root 1001 0 Jun  8  2018 samba-user-3

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *