2023-09-19 09:00:00
File sharing is an essential part of server administration. It allows sharing resources over the network that users need to perform their tasks. One of the most used file sharing programs is Samba .
Samba a reimplementation of the popular protocol SMB ( server message block ), is a stable and free application that allows file sharing and printing services over a network. The software is installed on a central Linux server from which shared files can be accessed from Linux and Windows systems.
In this guide, we will walk you through installing the Samba server on RHEL based distributions like CentOS Stream , Rocky Linux y AlmaLinux .
Step 1: Install Samba on Linux
To start with Samba install the main packages from Samba, including the client package:
$ sudo dnf install samba samba-common samba-client
Install Samba on Linux
The command installs the specified packages along with dependencies as shown in the output. Once the installation is complete, you will get a summary of all the packages that have been installed.
Samba installation completes
Step 2: Create and configure Samba shares
Once all packages are installed of samba, the next step is to configure the samba shared resources . A Samba share is simply a directory that will be shared between client systems on the network.
Here, we are going to create a samba share called /data in directory path /srv/lparty01/ .
$ sudo mkdir -p /srv/lparty01/data
Next, we will assign permissions and ownership as follows.
$ sudo chmod -R 755 /srv/lparty01/datos
$ sudo chown -R nobody:nobody /srv/lparty01/data
$ sudo chcon -t samba_share_t /srv/lparty01/data
Create Samba Shared Directory
Next, let’s make some settings in the configuration file smb.conf which is the main Samba configuration file. But before doing so, we will backup the file by renaming it with a different file extension.
$ sudo mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
Next, let’s create a new configuration file.
$ sudo vim /etc/samba/smb.conf
We will define policies on who can access the samba share by adding the lines shown in the configuration file.
[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/lparty01/datos
browsable =yes
writable = yes
guest ok = yes
read only = no
Save and exit the configuration file.
To verify the configurations made, run the command:
$ sudo testparm
Verify Samba Configuration
Next, start and enable the Samba daemons as shown.
$ sudo systemctl start smb
$ sudo systemctl enable smb
$ sudo systemctl start nmb
$ sudo systemctl enable nmb
Be sure to confirm that the demons smb y nmb are being executed.
$ sudo systemctl status smb
$ sudo systemctl status nmb
Check Samba Status
To enable access to the samba share from remote Windows systems, you must open the samba protocol in the firewall.
$ sudo firewall-cmd –permanent –add-service=samba
$ sudo firewall-cmd –reload
$ sudo firewall-cmd –list-services
Step 3: Access Samba Share from Windows
So far, we have installed samba and configured our samba share . Now we are ready to access it remotely. To do this on a Windows client, press Windows logo key + R to launch the dialog box Execute .
In the text field provided, enter the IP address of the samba server as shown:
\IP_servidor
Access Samba Share from Windows
The following window will appear called ” Public “. Remember, this is the directory that points to our samba share in the directory /srv/lparty01/data .
Access the Samba Shared Directory on Windows
Currently, our directory is empty because we have not created any files. So, we’ll go back to our terminal and create some files in the samba shared directory.
$ cd /srv/lparty01/datos
$ sudo touch file{1..3}.txt
Now, we will navigate to the folder ‘ Public ‘ where the files we created previously will be displayed.
Access shared Samba files on Windows
Perfect. We have successfully managed to access our shared resource s both . However, our directory is accessible to anyone and everyone can edit and delete files at will, which is not recommended, especially if you plan to host sensitive files.
In the next step, we will demonstrate how you can create and configure a samba secure shared directory.
Step 4: Protect the Samba Shared Directory
First, we will create a new samba user.
$ sudo useradd smbuser
Next, we will set a password for the samba user. This is the password that will be used during authentication.
$ sudo smbpasswd -a smbuser
Create Samba user
Next, we will create a new group for our samba secure share and add the new samba user.
$ sudo groupadd smb_group
$ sudo usermod -g smb_group smbuser
Next, create another samba share that will be securely accessible. In our case, we have created another directory in the same path as the
$ sudo mkdir -p /srv/lparty01/private
Then set the file permissions for the samba share.
$ sudo chmod -R 770 /srv/lparty01/private
$ sudo chcon -t samba_share_t /srv/lparty01/private
$ sudo chown -R raíz:smb_group /srv/lparty01/private
Once again, access the Samba configuration file.
$ sudo vim /etc/samba/smb.conf
Add these lines to define samba secure sharing.
[Private]
path = /srv/lparty01/private
valid users = @smb_group
guest ok = no
writable = no
browsable = yes
Save changes and exit.
Finally, restart all samba daemons as shown.
$ sudo systemctl restart smb
$ sudo systemctl restart nmb
When you access your server this time, you will notice a folder ‘ Private ‘additional. To access the folder, you will be asked to authenticate with the Samba user credentials. Provide the username and password of the user you created in the previous step and click ‘ Accept ‘.
Samba user authentication
Samba private shared directory
Step 5: Access Samba Share from the Linux client
To access the share from a Linux client, first ensure that the Samba client package is installed.
$ sudo dnf install samba-client
Then use the command smbclient as follows
# smbclient ‘2.168.43.121private’ -U smbuser
Access Samba Share from Linux
And that concludes this guide on how to configure Samba in RHEL , CentOS Stream , Rocky Linux y AlmaLinux . His comments on this guide will be greatly appreciated.
#configure #Samba #server #RHEL #Rocky #Linux #AlmaLinux