Home CentOS Stream How to Install Samba on RHEL and CentOS Stream

How to Install Samba on RHEL and CentOS Stream

Operating system users might have different egoistic opinions on which operating system distribution is better but always find a common ground when it comes to issues like finding ideal file sharing solutions.

Samba is such a solution. Whether you are on a Windows or Linux operating system environment, Samba makes it possible to flexible share files among remote operating system users.

[ You might also like: How to Reset Forgotten Root Password in RHEL 8 ]

Samba’s GPL license attributes it as an open-source project. Through the SMB (Server Message Block) protocol, users not only benefit from Samba’s remote file-sharing capabilities but also its file printing services. Samba is packaged as both server and client software making it compatible with any operating system architecture.

This article is going to take us through installing, configuring, and testing Samba on RHEL and CentOS Stream and also figure out how to share some files if possible from Windows machine.

Installing Samba on RHEL 8

To install Samba and its client software on RHEL 8, execute the following command on the terminal.

$ sudo dnf install -y samba samba-client
Install Samba in RHEL
Install Samba in RHEL

Note that this installation does not necessarily need samba-client but its consideration comes with some very useful utilities.

Once the two samba packages are installed successfully, take note of some daemons we need to start and enable. The first daemon; smb, handles file transfer and sharing operations.

The second daemon; nmb, handles NetBIOS name resolutions. It makes it possible for a shareable resource to be visible for users who want to browse them.

The command for enabling these two daemons is as follows:

$ sudo systemctl enable --now {smb,nmb}
Enable Samba In RHEL
Enable Samba In RHEL

Enable Samba on FirwallD in RHEL 8

Firewall configuration is necessary for users on remote machines to easily and flexibly access samba-shared resources through appropriate ports. We can achieve this objective through firewalld.

We can query firewalld to tell us what info it has on Samba file-sharing service.

$ sudo firewall-cmd --info-service samba
Check Samba Info in Firewalld
Check Samba Info in Firewalld

The above screen capture tells us that Samba only recognizes ports 137/udp, 138/udp, 139/tcp, and 445/tcp for file-sharing traffic. To permanently add Samba service to firewalld, execute the following command:

$ sudo firewall-cmd --permanent --add-service=samba 

For the above-implemented change to be effective, reload the system firewall.

$ sudo firewall-cmd --reload

Verify Samba’s inclusion by the firewall.

$ sudo firewall-cmd --list-services 
Check Samba in Firewalld
Check Samba in Firewalld

Configuring Samba Users Shared Directory

For any user to access a shareable directory via Samba without passing through user authentication (password), open the file /etc/samba/smb.conf and trace the [global] section.

$ sudo nano /etc/samba/smb.conf

Add the line:

map to guest = bad user

An access attempt with the default username nobody will grant anyone passwordless access to shareable files.

A new stanza is needed to define the path to shareable files. We have also added the writeable limitation so that the guest users can only read shared files.

[linuxshelltips]
        path = /home/dnyce/Desktop/shareable
        guest only = yes
        writeable = no
Configure Samba Share in RHEL
Configure Samba Share in RHEL

The final piece of this setup is restarting the smb and nmb daemons.

$ sudo systemctl restart {smb,nmb}

Creating Samba Users for Shared Directory

Since this user requires access credentials to read and write shared files, it is advisable to create a dedicated user credential.

$ sudo adduser -M samba_user -s /sbin/nologin 
$ sudo smbpasswd -a samba_user

The above command also enables you to assign this Samba user his/her password. We also need to make some additional edits on the file /etc/samba/smb.conf.

Changing the line guest only = yes to guest ok = no permits access to registered users only.

Enable Samba Access to Users
Enable Samba Access to Users

Finally, execute testparm to be certain there is no syntax error in your Samba configuration.

$ testparm
Check Samba Configuration
Check Samba Configuration

Accessing Samba Shares from Windows Machine

Once you log in on your Windows OS, right-click anywhere on its Desktop to create a shortcut.

Create Desktop Shortcut in Windows
Create Desktop Shortcut in Windows

When asked for the location of the item, it should adhere to the following syntax:

\\RHEL8_IP_Address\SHARE_NAME

The SHARE_NAME in this case is linuxshelltips.

\2.168.1.144\linuxshelltips
Create Samba Share in Windows
Create Samba Share in Windows

In the next interface, you can decide to create a custom name for this Samba shortcut.

Set Samba Share Name
Set Samba Share Name

You will be asked to enter your Samba username and password. Finally, the shortcut to shareable files on RHEL 8 will be created. All files and directories you add on this RHEL8 shareable folder will be accessible to valid Samba users on Windows operating systems.

Sharing Samba Files in Windows
Sharing Samba Files in Windows

This article guide has successfully covered Samba installation, configuration, and testing. You can now comfortably add and share files with guests and registered users on other operating system environments like Windows OS at the comfort of your RHEL 8 system.

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. Founder of TecMint.com, LinuxShellTips.com, and Fossmint.com. Over 150+ million people visited my websites.

Each tutorial at UbuntuMint is created by a team of experienced writers so that it meets our high-quality standards.

Was this article helpful? Please add a comment to show your appreciation and support.

Got something to say? Join the discussion.

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published or shared. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.