Setting up Samba on Red Hat Linux Servers

Voiced by Amazon Polly

In this article, we will be covering setting up Samba on Red Hat Linux servers. This will allow sharing within Linux and Windows shares. Samba is used many times in mixed enviornments with Linux and Windows, and is an alternative to NFS.

Samba is an open-source software suite that runs on Unix/Linux based platforms but is able to communicate with Windows clients like a native application. So Samba is able to provide this service by employing the Common Internet File System (CIFS). At the heart of this CIFS is the Server Message Block (SMB) protocol


Initial steps in Setting up Samba on Red Hat Linux

We first need to setup our directory structure for our Samba share.

# mkdir -p /sambashare
# chmod 2770 /sambashare/
creating the samba share

SELinux and creating the sales group

We need to setup our share for SELinux (you are running SELinux right?).

# semanage fcontext -at samba_share_t '/sambashare(/.*)?'
# restorecon -vvFR /sambashare

Then we are going to set up our sales group.

# groupadd sales
# chgrp sales /sambashare/
setting up selinux and the sales group

Creating samba only users

We will add some users, some will be part of our sales group, while others will not. The ones in the sales group will have access to this particular share we are setting up.

# useradd -s /sbin/nologin -G sales calvin
# useradd -s /sbin/nologin -G sales daphne
# useradd -s /sbin/nologin penny
adding the users

Installing Samba server packages

Next we will install the samba server and client packages on our server.

# yum install samba samba-client
installing samba and samba-client
# smbpasswd -a calvin
# smbpasswd -a penny

We will set each user to the password “redhat”.

setting the passwords with smbpasswd

Setting up the firewall

We need to open up the samba port to allow samba to work properly.

# firewall-cmd --permanent --add-service=samba
# firewall-cmd --reload
setting up the firewall on the server for samba.

Editing the smb.conf file

# vim /etc/samba/smb.conf
editing the smb.conf file.

At the end of the conf file we add the information for our samba share. The share name first [smbshare], followed by the path of the share on the server, and the write list points to @sales, so that anyone in the sales group can read and write to the share.

Adding the samba share information to the samba.conf file.

Enabling smb and nmb

We need to enable and start the samba services next.

# systemctl enable smb nmb
# systemctl start smb nmb
enabling and staring the smb and nmb services on the server.

Preparing the client for the samba share

Next, we switch over to the client to perform the required tasks to mount our share and be ready for use.

# mkdir -p /mnt/sales
Adding the mount point on the client.

We then need to edit the /etc/fstab file.

# vim /etc/fstab

The server we are connecting to is //code and the share name as you recall is smbshare. The mount point on the client is /mnt/sales, and the protocol is cifs. The options we chose are credentials=/root/smb-multiuser.txt,multiuser,sec=ntlmssp 0 0

We need to remember to install the gifs-utils and create our multiuser.txt file before attempting to mount this volume however.

adding the mount info in the fstab file.

Installing cifs-utils

We need to install the cifs-utils so we are able to mount our share on the client.

# yum install cifs-utils.x86_64
installing cifs-utils on the client

Next, we need to set up that text file which will hold the credentials for our samba share.

# vim /root/smb-multiuser.txt

Inside the text file, add username=calvin and password=redhat

creating the multiuser text file for our share.

Installing the samba client package

Our last package we need to make this all work is the samba-client package on our client server.

# yum install samba-client
installing the samba-client package on the client.

Once this is finished, we can mount our share and verify.

# mount -a
# df -h

As you can see, our samba mount is now available. It shows the total size of 22G with 19G available.

mounting the samba share with mount -a

Ivan Windon

Ivan Windon is a Lead Engineer at Verizon Enterprise Solutions. Ivan is actively engaged in Cloud Technologies with AWS, Google, and Azure. Ivan has extensive experience with Linux and Windows administration, DNS, Networking, IDM, and Security. In his free time, he enjoys being with his wife and two children. The family enjoys hiking, and traveling when able. His favorite locations are Yosemite NPS, and San Francisco, California.

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: