How to Setup Samba File Sharing Server on RHEL 8 (CentOS/AlmaLinux/Rocky Linux)

How to Setup Samba File Sharing Server on RHEL 8

Have you ever wanted to share a file on your local area network with another user and make that file available with no network restriction for Windows, macOS, and Linux systems?

This article will give you a step-by-step guide on installing and setting up Samba file sharing on RHEL 8 distros, such as CentOS 8, Rocky Linux 8, and AlmaLinux 8.

That will give other users on your LAN easy access to your files. Samba is a free software application that helps Linux servers to share resources and files with other clients such as windows clients, Mac, and other distributions.

Samba applications use TCP/IP for sharing data between the cross-platform servers. It is implemented using CIFS and SMB protocols. CIFS stands for Common Internet File System, while SMB stands for Server Message Block.

With that in mind, let’s dive in and get started.

Step 1: Install Samba on RHEL 8

We first need to install several required RPM packages to set up a working Samba file sharing Server to get started. These packages include

  • Samba: This is the main package needed to run the Samba Server.
  • Samba-client: This package is required to run samba-client.
  • Samba-common: This package comes with all the commands and utilities required to configure Samba.
  • Samba-winbind: This package creates a connection between Linux and Windows systems.
  • Samba-domain-join-GUI: As we will see below, Samba sharing works with the help of Workgroups and Domains. This package creates a connection between Windows domains and workgroups.
  • Samba-doc: This package contains Samba user manuals and help documents.

Execute the command below to install all these packages.

sudo yum install samba samba-client samba-common samba-winbind

word image 19

Once done, you can confirm whether the packages were installed successfully by running the commands below.

rpm -qa samba
rpm -qa samba-common
rpm -qa samba-wi*

word image 20

From the image, you can see all the required packages are installed.

Step 2. Check Samba Services

There are three primary services required to configure Samba. They include

  • Smb: This service provides authentication and authorization between Windows and Linux systems.
  • Nmb: Also known as nmbd, nmb is a server that understands and replies to NetBIOS requests.
  • Winbind: This service acts as a DNS server and is needed for username and host resolution.

Execute the commands below to start the services on your system.

sudo service smb start
sudo service nmb start
sudo service winbind start

word image 21

When done, run the commands below to confirm whether the services are running on your system.

sudo service smb status
sudo service nmb status
sudo service winbind status

word image 22

From the image above, you can see the notification active (running). That means the services are up and running.

We need to enable these services to start on boot whenever we shut down or restart our PC and allow the services through the system firewall.

Execute the commands below to run the Samba services on boot.

sudo chkconfig smb on
sudo chkconfig nmb on

word image 23

To enable the services through firewall, execute the commands below:

sudo firewall-cmd --permanent --zone=public --add-service=samba
firewall-cmd --reload

word image 24

Step 3. Create Users

Now, we need to create users who will access the Samba services from other PCs on the network. Generally, whenever you try to connect to the Samba file server, you will be required to authenticate using a username and password. The users we will create in this step are the ones you will use for authentication.

Execute the command below to add two users.

sudo useradd JohnDoe
sudo useradd JaneDoe

word image 25

To create authentication passwords for the new users, we will use the command below.

smbpasswd -a [user]
smbpasswd -a JohnDoe
smbpasswd -a JaneDoe

word image 26

Step 4. Configure Samba

Up to this point, we have all the required packages installed and users created – we can now configure Samba. We need to create a directory where users will read or write data to get started.

We will create two folders in the home directory – SambaPublic and SambaPrivate folders. The SambaPublic folder will be accessible by all network members, whereas the SambaPrivate folder will only be accessible by authorized users. Execute the command below.

cd ~
sudo mkdir SambaPublic
sudo mkdir SambaPrivate
sudo chmod 777 SambaPublic
sudo chmod 777 SambaPrivate

word image 27

Let’s create some dummy data inside this SambaShare directory that we will use to test our connections. Execute the commands below.

cd SambaPublic
sudo touch FileOne FileTwo FileThree Image1 Image2 Image3
cd ..
cd SambaPrivate
sudo touch textOne textTwo textThree Doc1 Doc2 Doc3

word image 28

Alternatively, you can copy existing files on your system that you wish to share with other users to this newly created directory.

Next, we need to edit the Samba configuration file “smb.conf” present in the /etc/samba directory. First, create a backup of this file so that you can revert your changes in case of any configuration errors.

Execute the commands below.

sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.backup
sudo nano /etc/samba/smb.conf

In the file that will open, scroll down and look for the workgroup variable in the [global] section, which is by default set to SAMBA. See the image below.

word image 29

Edit the value to your Workgroup name. We will use the Workgroup name BYTEXD for this post.. Additionally, edit the passdb backend value to smbpasswd instead of tdbsam. See the image below.

word image 30

Scroll to the bottom of the file and paste the contents below to set the configurations for the SambaPublic folder.

[SambaPublic]
    comment=private samba share
    path=/root/SambaPublic
    public=yes
    browseable=yes
    writeable=yes

word image 31

Let’s go through the code above.

  • path = /root/SambaPublic: This is the path to the public folder
  • public = yes: This means that the folder is accessible to everyone on the network.
  • browseable = yes: this means that the file can be browsed
  • writable = yes: this means that the file can be read or written by anyone in the network.

Next, paste the code below to set configurations for the SambaPrivate directory.

[SambaPrivate]
    path=/home/private
    comment=private samba share
    public =no
    valid users=JohnDoe JaneDoe
    write list =JohnDoe
    read list =JaneDoe

word image 32

To explain for the private folder we have set the accessibility to no and only given access to JohnDoe and JaneDoe. We have also limited the user’s permissions to edit the folder by only giving JohnDoe the privileges to write.

Next, we will test whether our configurations were correct by using the following command below.

testparm

word image 33

From the image above, you can see we don’t have any errors in our smb.conf file. When we take a keen look at the SambaPublic, it has given guest ok = yes, meaning the folder is publicly accessible and read only = No, which means that everyone can edit.

Restart the Samba services to apply our new configurations using the commands below.

sudo service smb restart
sudo service nmb restart
sudo service winbind restart

Step 5. Stop Firewall Services and Disable SELinux

If you have enabled Firewall and SELinux security on your system, you need to disable them at this point so that we can test Samba’s share from other PCs on the network.

Execute the commands below to stop Firewall services.

sudo service iptables stop
sudo service iptables save

To disable SELinux, we will edit the SELinux config file and set SELINUX=disabled as shown below.

sudo nano /etc/selinux/config

word image 34

sudo reboot now

When done, we can now proceed to connect to Samba from other PCs on the network.

Step 6. Connect to Samba Share From Windows

To connect to Samba Share from a Windows system, you need to ensure that the Workgroup name set on your Windows machine is the same as the Workgroup we set on RHEL. For this post, we set the Workgroup as BYTEXD.

To set Workgroup name on Windows, right-click on This PC > select Properties > Advanced System Settings > Computer Name. After changing the Workgroup name, you will be prompted to reboot the system to apply the changes.

word image 35

After successfully setting the Workgroup name, open the command prompt and ping the IP of the RHEL system. That will help us know whether the Windows system can see the RHEL Samba Share on the network.

Execute the command below.

ping [RHEL-IP-Address]

E.g.

ping 192.168.1.61

word image 36

From the image above, you can see we are getting replies from the RHEL machine. If that’s not the case for you, please ensure you are connected to the same network as the RHEL system.

Now to connect to the RHEL Samba Share, right-click on This PC and select the option, Add a network location. A window will pop up and you will see a wizard to add a network location. Click Next continuously until you are prompted to enter the internet or network address. Use the syntax below.

\\[RHEL-IPaddress]\[Samba-shared-folder]

E.g.

\\192.168.1.61\SambaPrivate

word image 37

When done, click Next. You will see a prompt to log in with a username and password. Use the users you created when configuring Samba on the RHEL system.

word image 38

After a successful login, a window will open showing the contents of the Samba share.

word image 39

Step 7. Connect to Samba Share from Linux

There are two ways you can connect to Samba share from a Linux system.

  • Command-line method
  • Graphical method

Command-line Method

We will first need to install the smbclient utility, which we will use to establish a connection to SambaShare. If you are on a Debian-based system, execute the command below.

sudo apt install smbclient

If you are connecting from an RHEL-based system., install smbclient by executing the command below.

sudo yum install samba-client

To access the Samba share from the command-line, use the syntax below.

smbclient //[RHEL-IP]/[Shared-Folder] -U [username]

E.g.

smbclient //192.168.1.61/SambaPublic -U JohnDoe

word image 40

You can now execute commands from the smb: \> terminal prompt. Unfortunately, not all Terminal commands will work here. Type help to see all the commands you can execute in the Samba share.

word image 41

Graphical Method

If you are not well versed with the Linux Terminal, you can access the Samba share from your Graphical user interface. Follow the steps below.

  1. Launch the file manager and click Other Locations.
  2. At the bottom of the window, you will see the option Connect to Server. Type the address of the Samba share using the syntax below.
smb://[RHEL-IP-address/[Shared-Folder

E.g.

smb://192.168.1.61/sambapublic/

word image 42

  1. When done, click Connect. A window will pop up, and you will be prompted to enter a username and password. Use the credentials that you created when setting up Samba on RHEL. Use the option Registered User.
    word image 43
  2. Click Connect when done. If the credentials were correct, you should see the Shared Folder open in a new window, as shown in the image below.
    word image 44

Conclusion

That’s it! If you followed the whole post, I believe you now have a working Samba File Sharing server setup on your RHEL system. You can now play around by creating more users and Shared folders. If you encounter any errors while executing any of the commands above, please let us know in the comments.

0 Shares:
Subscribe
Notify of
guest
Receive notifications when your comment receives a reply. (Optional)
Your username will link to your website. (Optional)

2 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
kunal janjal
kunal janjal
8 months ago

sir i can’t able to ping my rhel 8 ip on windows coomand prompt….can you give me any suggestion

Last edited 8 months ago by kunal janjal
DEEP
4 months ago

sir i can’t able to ping my rhel 8 ip on windows coomand prompt.

You May Also Like