Samba – How to set up a Samba client on CentOS/RHEL 7

If you have directories on your machine that you want to share out to other machines then you can do this by setting up your machine as an NFS server. However with NFS you can only share out folders to machine that are in the same private network. If you want share folders to other machines over the public internet, then that’s where you need to use the Samba/CIFS protocol. You can follow along this article using this vagrant project on Github.

We will walk through the following example:

+--------------------------+              +--------------------------+
|                          |              |                          |
|      samba-storage       |              |       samba-client       |
|     (IP: 10.0.4.10)      |              |                          |
|                          |              |                          |
|                          |              |                          |
|                          |              |                          |
|  +------------------+    |              |     +---------------+    |
|  | /samba/export_rw |<----------------------->| /mnt/backups  |    |
|  +------------------+    |              |     +---------------+    |
|                          |              |                          |
|                          |              |                          |
+--------------------------+              +--------------------------+

In this article we’ll cover setting up the samba client side. We cover setting up a Samba server in a separate article. First you need to install the samba software:

$ yum -y install samba samba-client cifs-utils

Note: It’s recommended to install the samba server software on all samba clients.

Then we create our mount point:

$ mkdir -p /mnt/backups

Next we need check if we can connect to the samba server, and if we can to also check what shares are available:

$ smbclient -L //samba-storage.local -U samba_user1
Enter SAMBA\samba_user1's password:
Domain=[SAMBA-STORAGE] OS=[Windows 6.1] Server=[Samba 4.6.2]

	Sharename       Type      Comment
	---------       ----      -------
	print$          Disk      Printer Drivers
	bckp_storage    Disk      Folder for storing backups
	IPC$            IPC       IPC Service (Samba server samba-storage)
	samba_user1     Disk      Home Directories
Domain=[SAMBA-STORAGE] OS=[Windows 6.1] Server=[Samba 4.6.2]

	Server               Comment
	---------            -------

	Workgroup            Master
	---------            -------

Now we can test this by manually mounting this share like this:

$ mount -t cifs -o user=samba_user1,password=password123 //samba-storage.local/export_rw /mnt/export/

You can check if this command has worked using the df:

$ df -h
Filesystem                          Size  Used Avail Use% Mounted on
/dev/mapper/centos-root              41G  1.2G   40G   3% /
devtmpfs                            486M     0  486M   0% /dev
tmpfs                               497M     0  497M   0% /dev/shm
tmpfs                               497M  6.7M  490M   2% /run
tmpfs                               497M     0  497M   0% /sys/fs/cgroup
/dev/sda1                          1014M  153M  862M  16% /boot
/dev/mapper/centos-home              20G   33M   20G   1% /home
vagrant                             466G   58G  409G  13% /vagrant
tmpfs                               100M     0  100M   0% /run/user/1000
tmpfs                               100M     0  100M   0% /run/user/0
//samba-storage.local/bckp_storage   41G  1.2G   40G   3% /mnt/backups

You can find out more about cifs mount option in the man pages:

$ man mount.cifs

To unmount this, do:

$ umount /mnt/backups 

If you has, then you automount this samba share at boot time by adding the following entry to the /etc/fstab file:

//samba-storage.local/bckp_storage /mnt/backups  cifs  username=samba_user1,password=password123,soft,rw  0 0

To test this line, just run:

$ mount -a

Then check again if this has mounted successfully. If all is well try creating dummy content in the mountpoint and see if the content also shows up on the samba server.

Take the RHCE Quiz

This article is part of our RHCE Study guide (click on the yellow tab on the far left). By the end of this article you should be able to answer the following questions:


What rpms do you need to install?

$ yum -y install samba samba-client cifs-utils

What is the command to manually test the samba access?

$ smbclient -L //samba-storage.local -U samba_user1

What is the command to view more info about the samba mount options?

$ man mount.cifs

What is the command to manually mount the samba share, //samba-storage.local/export_rw onto the mountpoint /mnt/export/, with username=samba_user1 and password=password123?

$ mount -t cifs -o user=samba_user1,password=password123 //samba-storage.local/export_rw /mnt/export/

what entry needs to be added to the /etc/fstab file?

//samba-storage.local/bckp_storage /mnt/backups cifs username=samba_user1,password=password123,soft,rw,_netdev 0 0

# Notice how we specify the fqdn of the remote folder. We didn’t use a colon. Also we didn’t specify remote folder path.