How to Install Samba Server in RHEL, CentOS and Fedora

Samba is an open-source and most popular widely used program that enables end-users to access Linux shared directory from any Windows machine on the same network.

Samba is also named as a network file system and can be installed on Linux/Unix operating systems. Samba itself is a client/server protocol of SMB (Server Message Block) and CIFS (Common Internet File System).

Using Windows smbclient (GUI) or file explorer, end users can connect to the Samba server from any Windows workstations to access shared files and printers.

This tutorial explains how to install Samba Server (fileserver) on RHEL, CentOS Stream, and Fedora systems, and also we will learn how to configure it to share files over the network using SMB protocol, as well as we will see how to create and add system users on samba user’s database.

[ You might also like: How to Setup Samba Server in RHEL, Rocky Linux and AlmaLinux ]

For demonstration, we are using RHEL 8 system with hostname tecmint with IP address 192.168.43.121.

Install and Configure Samba in RHEL

To get started with samba, you need to install the samba core packages and samba-client package as shown:

# dnf install samba samba-common samba-client 
Install Samba in RHEL
Install Samba in RHEL

After all the samba is installed, you need to configure the samba share directory with proper permissions and ownership, so that it is going to be shared with all client machines in the same local network.

# mkdir -p /srv/tecmint/data
# chmod -R 755 /srv/tecmint/data
# chown -R  nobody:nobody /srv/tecmint/data
# chcon -t samba_share_t /srv/tecmint/data
Create Samba Share Directory
Create Samba Share Directory

Next, we are going to configure the Samba share directory in the smb.conf file, which is the main configuration file for Samba.

# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
# vim /etc/samba/smb.conf

Add the following configuration lines, which define the policies on who can access the samba share on the network.

[global]
workgroup = WORKGROUP
server string = Samba Server %v
netbios name = rocky-8
security = user
map to guest = bad user
dns proxy = no
ntlm auth = true


[Public]
path =  /srv/tecmint/data
browsable =yes
writable = yes
guest ok = yes
read only = no

Save and exit the configuration file.

Next, verify the samba configuration for errors.

# testparm
Test Samba Configuration
Test Samba Configuration

If everything looks okay, make sure to start, enable and verify the status of the Samba daemons.

# systemctl start smb
# systemctl enable smb
# systemctl start nmb
# systemctl enable nmb
# systemctl status smb
# systemctl status nmb
Start Samba Services
Start Samba Services

Accessing Samba Share from Windows

To access Samba share from the Windows machine, press the Windows logo key + R to launch the Run dialog and enter the IP address of the samba server as shown.

Access Samba Share from Windows
Access Samba Share from Windows

Once you connected, you will be presented with the ‘Public’ directory of our samba share from the /srv/tecmint/data directory.

Samba Share Directory
Samba Share Directory

The ‘Public’ directory is empty, as we don’t have created any files in the Samba share, let’s create a few files with the following command.

# cd /srv/tecmint/data
# touch file{1..3}.txt

Once you have created files, try accessing the Samba ‘Public‘ folder to view the files.

View Samba Share Files
View Samba Share Files

We have successfully configured and accessed our samba share from Windows, However, our directory is accessible to anyone with the permissions to edit and delete files, which is not recommended when you are hosting important files.

In the next section, you will learn how to secure your samba share directory.

Secure Samba Share Directory in RHEL

To secure our Samba share, we need to create a new samba user.

# useradd smbuser
# smbpasswd -a smbuser

Next, create a new group and add the new samba user to this group.

# sudo groupadd smb_group
# sudo usermod -g smb_group smbuser

Thereafter, create another secure samba share directory for accessing files securely by samba users.

# mkdir -p /srv/tecmint/private
# chmod -R 770 /srv/tecmint/private
# chcon -t samba_share_t /srv/tecmint/private
# chown -R root:smb_group /srv/tecmint/private

Once again, access the Samba configuration file.

# vi /etc/samba/smb.conf

Add these lines to define to secure samba share.

[Private]
path = /srv/tecmint/private
valid users = @smb_group
guest ok = no
writable = no
browsable = yes

Save the changes and exit.

Finally, restart all the samba daemons as shown.

$ sudo systemctl restart smb
$ sudo systemctl restart nmb

Now try to access the Samba share, this time you will see an additional ‘Private‘ directory. To access this directory, you will be required to authenticate with the Samba user’s credentials as shown.

Samba User Login
Samba User Login

To access the samba share from a Linux machine, first, install the samba-client package and try to connect.

# dnf install samba-client 
# smbclient ‘\2.168.43.121\private’ -U smbuser
Access Samba Share from Linux
Access Samba Share from Linux

And this concludes this article on installing and configuring up Samba on RHEL, CentOS Stream, and Fedora. Your feedback on this article will be highly appreciated.

If you read this far, tweet to the author to show them you care. Tweet a thanks
Ravi Saive
I am an experienced GNU/Linux expert and a full-stack software developer with over a decade in the field of Linux and Open Source technologies

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

Join the TecMint Weekly Newsletter (More Than 156,129 Linux Enthusiasts Have Subscribed)
Was this article helpful? Please add a comment or buy me a coffee to show your appreciation.

16 thoughts on “How to Install Samba Server in RHEL, CentOS and Fedora”

  1. Actually I have configure the samba server but i enter the command smbclient -L //tecmint/tecmintusers -U tecmint then a error message show

    Error NT_STATUS_BAD_NETWORK_NAME

    Reply

Got something to say? Join the discussion.

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.