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

Then we create a group that mirrors the same group that existing on the samba server:

$ groupadd --gid 2000 sambagroup

Now we need to add members to that group, in our case we’ll add the root user:

$ usermod -aG sambagroup root

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 mount or df -h commands.

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 using mount or df -h commands. If all is well try creating dummy content in the mountpoint and see if the content also shows up on the samba server.