In this post, we will explain how to install Samba Server on Rocky Linux 9 or AlmaLinux 9 step-by-step.
Samba is a popular file-sharing open-source application that enables the sharing of network resources required by users to complete their tasks. It is a re-implementation of the popular SMB (server message block) protocol that provides network file and print sharing.
Samba is deployed on a central Linux server, whereupon shared resources are stored and accessed from a Linux or Windows client.
- Pre Installed Rocky Linux 9 or AlmaLinux 9
- A Regular user with sudo rights
- Internet Connectivity
1) Update the Server Packages
To get off the ground, first, confirm that our server is up to date and that all the packages are up to their most recent versions. To do so, run the following command.
$ sudo dnf -y update
Reboot your system after installing all the available updates.
$ sudo reboot
2) Install Samba Server on Rocky Linux 9 / AlmaLinux 9
The samba packages are available in the Alma/Rocky Linux default package repositories. To Install them, execute the command as shown.
$ sudo dnf install samba samba-common samba-client -y
The command installs the packages requested as well as the dependencies shown in the output. You will receive a list of all the packages that have been successfully installed once the installation is complete.
3) Creating and Configuring Samba shares
A samba share is essentially a directory that will be shared among network client systems. Therefore, we’ll create a directory as shown.
$ sudo mkdir -p /home/linuxbuzz/sambashare
Now, we’ll assign permission and ownership to the directory we just created so that it can be accessible.
$ sudo chmod -R 755 /home/linuxbuzz/sambashare $ sudo chown -R nobody:nobody /home/linuxbuzz/sambashare $ sudo chcon -t samba_share_t /home/linuxbuzz/sambashare
Next, we’ll make some changes to the smb.conf configuration file, which serves as Samba’s primary configuration file. But before we get to that, we’ll create a backup file so that in case we mess up, we have a copy.
$ sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bk
Let us now create a new configuration file by running the following command in our terminal:
$ sudo vim /etc/samba/smb.conf
Next, add the following parameters to the configuration file in order to determine who can access the Samba share.
[global] workgroup = WORKGROUP server string = Samba Server %v netbios name = rocky-9 security = user map to guest = bad user dns proxy = no [Public] path = /home/linuxbuzz/sambashare browsable =yes writable = yes guest ok = yes read only = no
To save and exit the configuration file, use the:wq! command.
In order to verify the configuration file, execute the command as shown:
$ sudo testparm
4) Start and Enable the Samba Service
By default, the services will not be started. Start the services with the following command:
$ sudo systemctl start smb $ sudo systemctl start nmb
To enable the services to start on boot, execute the command as shown:
$ sudo systemctl enable smb $ sudo systemctl enable nmb
To confirm if the services are up and running in the background, use the following commands:
$ sudo systemctl status smb $ sudo systemctl status nmb
The above outputs indicate the services are running. Now let’s enable the samba protocol on the firewall in order to allow remote Windows PCs to access samba shares.
$ sudo firewall-cmd --permanent --add-service=samba $ sudo firewall-cmd --reload
5) Access the Samba shares From the Linux Client
To access the file system from a Linux client, the Samba client application must be installed. Run the following command to install the program on your Linux system:
$ sudo dnf install samba-client
Now, if you want to access the Samba share, execute the command as shown:
$ sudo smbclient -L //server-ip/Public
6) Accessing Samba Share from Windows
To access the share from this destination, open the Run dialog on a Windows client by hitting the Windows Key + R.
Enter the IP address or hostname of your server in the space provided, as follows:
The above action prompts shares to be opened, and you can add a file or directory to the repository from either a Windows client computer or a Linux server.
Now let’s see how you can secure the Samba Share Directory.
7) Secure Shamba Share
Samba permits both private and public shares, where access to the shares is without verification. In this section, we will configure Samba to share a secure directory that only authorized users can access.
Let’s first create a new Samba user on our Server.
$ sudo useradd smbuser
We will then set up the password that will be used for verification.
$ sudo smbpasswd -a smbuser
We will then add the new Samba user to a new group we just created, as shown:
$ sudo groupadd smb_group $ sudo usermod -g smb_group smbuser
Let’s now create a secure directory in the same path as we stated above and go ahead to give the folder permissions and ownership as follows:
$ sudo mkdir -p /home/linuxbuzz/sambashare $ sudo chmod -R 770 /home/linuxbuzz/sambashare $ sudo chown -R root:smb_group /home/linuxbuzz/sambashare $ sudo chcon -t samba_share_t /home/linuxbuzz/sambashare
Now, once again, let’s go back to the Samba configuration file.
$ sudo vim /etc/samba/smb.conf
Add the lines below to define the Samba share:
Save and exit the window.
For configurations to take effect, restart Samba services.
$ sudo systemctl restart smb $ sudo systemctl restart nmb
This time, when you log in to your Windows client and go to the “Private” folder, You will need to authenticate using the Samba user’s credentials in order to access the folder. Enter the user’s username and password from the previous step and press “OK.”
There you go! We were able to install Samba and configure it so that our Rocky/Alma Linux OS could share files securely and anonymously with other Linux or Windows desktop clients.