[powerkit_collapsibles]
[powerkit_collapsible title=”Not using a RHEL 8 distro? Choose a different version or distro.”]
How to Setup Samba Server on Ubuntu 20.04
[/powerkit_collapsible]
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
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*
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
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
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
To enable the services through firewall, execute the commands below:
sudo firewall-cmd --permanent --zone=public --add-service=samba firewall-cmd --reload
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.
[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Note: Do not create passwords for these users using the system passwd command. Instead, we will create passwords using the smbpasswd utility to ensure the users only access Samba services and not the entire system.
[/powerkit_alert]
sudo useradd JohnDoe sudo useradd JaneDoe
To create authentication passwords for the new users, we will use the command below.
smbpasswd -a [user] smbpasswd -a JohnDoe smbpasswd -a JaneDoe
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
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
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.
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.
[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Note: Ensure you have created the same Workgroup name on your Windows system. If you don’t know how to do this, you can check Step 6 below.
[/powerkit_alert]
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
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
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
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.
[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Tip: Alternatively, if you don’t want to disable Firewall and SELinux security features, please jump to Step 7 below where we have detailed the policies that we need to allow in the system Firewall and SELinux for SAMBA to work.
[/powerkit_alert]
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
[powerkit_alert type=”info” dismissible=”false” multiline=”false”]
Note: Reboot the system to apply the changes. You can easily do so by executing the command below.
[/powerkit_alert]
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.
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
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
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.
After a successful login, a window will open showing the contents of the Samba share.
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
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.
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.
- Launch the file manager and click Other Locations.
- 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/
- 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.
- 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.
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.
sir i can’t able to ping my rhel 8 ip on windows coomand prompt….can you give me any suggestion
sir i can’t able to ping my rhel 8 ip on windows coomand prompt.