Install Samba on RHEL-based Linux distributions

Image: joyfotoliakid/Adobe Stock

Samba is a key part of using Linux in a professional environment. With this subsystem, users can share directories on the network so that others can view and even modify the content they contain.

SEE: 40+ open source and Linux terms you need to know (TechRepublic Premium)

With some Linux distributions, like Ubuntu Desktop, many things are in place by default. Other distributions, such as those based on Red Hat Enterprise Linux, may not include everything needed to get Samba working out of the box. That’s what I’m here for: I want to walk you through the process of setting up and running Samba on RHEL-based Linux distributions.

What you’ll need to get Samba working on RHEL-based distributions

The only things you will need to install Samba are an RHEL-based Linux distribution and a user with sudo privileges. I’ll demonstrate with EuroLinux, but this process should work with just about any RHEL-based distro.

How to Install Samba

The first thing we need to do is install Samba. To do this, log into your Linux distribution and open a terminal. From the terminal window, run the command:

sudo dnf install samba samba-common samba-client -y

Make sure the service is started and enabled with:

sudo systemctl enable --now smb

That’s it for the install. Let’s create a share.

How to create a Samba share

Let’s create a share in /srv. To do this, create a new folder with the command:

sudo mkdir -p /srv/samba/euroshare

You can name the share in the samba directory whatever you want.

Give the new share the appropriate permissions with the following commands:

sudo chmod -R 755 /srv/samba/euroshare
sudo chown -R nobody:nobody /srv/samba/euroshare
sudo chcon -t samba_share_t /srv/samba/euroshare

Next, we will create a share from the smb.conf file. Open the file for editing with:

sudo nano /etc/samba/smb.conf

At the bottom of this file, add the following:

[Public]
path = /srv/samba/euroshare
public = yes
guest only = yes
writable = yes
force create mode = 0666
force directory mode = 0777
browseable = yes

Save and close the file. Restart Samba with:

sudo systemctl restart smb

How to adjust the firewall

Now we need to open the firewall so that Samba can be accessed. First, create the new firewall rule with:

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

Reload the firewall with:

sudo firewall-cmd --reload

At this point, the Samba share should be accessible from other machines on your network. And with the public smb.conf configuration, even anonymous users have read and write access to the share.

How to limit access to registered users

If you don’t want such broad access granted to the share, you can configure it so that only legitimate users can access the share. The only caveat to this is that the user will need to have an account on your machine. Of course, you can still create a sambashare user, so all you need to do is give that user’s credentials. To create the sambashare user, run the command:

sudo adduser sambashare

Be sure to give the user a strong/unique password.

Then give the new user a samba password with:

sudo smbpasswd -a sambashare

Then activate the user with:

sudo smbpasswd -e sambashare

Then the public smb.conf entry should look like this:

[Public]
path = /srv/samba/euroshare
browsable = yes
writable = yes
guest ok = yes
read only = no
create mask = 0644
directory mask = 2777

Next, we will need to give the sambashare user access to the folder with:

sudo chown -R sambashare /srv/samba/euroshare

Restart Samba with:

sudo systemctl restart smb

Now the sambashare user should have full access to the share.

And that’s how we do Samba-based Linux distribution with RHEL. You can now dance knowing that you have allowed users on your network access to the files and folders on it.

Subscribe to TechRepublic How to make the technology work on YouTube for all the latest tech tips for professionals from Jack Wallen.

Comments are closed.