In this article, you will learn to install Samba server on CentOS/RHEL 7 and basic file sharing configuration for the Windows machine.
Samba is an open-source software package. Also, it is free software and is available under the GNU (General Public License). So, you can modify and redistribute it. It uses the Server Message Block (SMB) and Common Internet File System (CIFS) as a protocol.
Samba is useful for file and print services. It supports different versions of Microsoft Windows operating systems, Mac operating systems, and Linux operating systems.
Samba Features
Samba is a powerful tool. So, it has many abilities. But, I’m listing some of them below.
- It can run as an Active Directory Domain Controller.
- Serve directory trees and printers to Linux, UNIX, and Windows clients.
- Assist in network browsing (with or without NetBIOS)
- Authenticate Windows domain logins
- Provide Windows Internet Name Service (WINS) name server resolution
- It acts as a Windows NT-style Primary Domain Controller (PDC)
- Act as a Backup Domain Controller (BDC) for a Samba-based PDC
- Act as an Active Directory domain member server
Samba Alternatives
There are some alternatives available for Samba. But, they do not have all the features like Samba. So, just for the knowledge, you can find it useful.
- NQE
- Power Broker Identity Services
- NFS
- RazDC
- Sharity
Preconditions
- A VPS or a local server on which CentOS/RHEL 7 is running.
- A Microsoft windows machine to verify the Samba server setup.
- You must log in with a root user or a user with sudo privilege to make the changes.
- Internet connection
Step 1: Update the Server To install samba server
So, it is a good practice to check the server for any pending updates. However, it is not necessary to update the server only for the Samba server. You can use the below command to check for system updates.
sudo yum update
If it is asking for permission, then press y for confirmation and then hit the enter key.
Step 2: Install the Samba server on CentOS/RHEL 7
So, as of now, the Samba software package is available in the default CentOS/RHEL 7 repository. But, to install it you have to use the below commands.
sudo yum install samba samba-client samba-common
In case, if it is asking for confirmation to install the software, press y to confirm and then press the enter key.
Step 3: Starting the Samba server services after install
So, after completing the installation process, now we have to start the Samba services. Also, we have to enable startup. The below command will start the service, and it will also enable the service to start automatically on the startup of the system at the same time.
sudo systemctl enable --now smb nmb
Note: The smb service helps to file sharing and printing services. And, it listens on TCP ports 139 and 445. However, the nmb service helps NetBIOS over IP naming services to clients. And, it listens on UDP port 137.
Step 4: Check the status of Samba services
So, it is time to confirm the status of the Samba services and whether it is running or not. Use the below command to verify that and also you can see it in the picture.
sudo systemctl status smb nmb

Step 5: Configuring the firewall for the Samba server
As you have installed Samba successfully, and you have also started the service of Samba. So, now you have to open the ports on the firewall to access the Samba services. Use the below command to complete the step.
sudo firewall-cmd --permanent --add-service samba
Also, reload the firewall service using the below command.
sudo firewall-cmd --reload
Step 6: Confirming the Windows machine workgroup
In this step, you have to check the Windows machine workgroup. It should be in the same workgroup as the CentOS server has configured. So, open the command prompt and use the below command to check it on the Windows machine.
net config workstation
Also, you can see the output in the below picture.

Step 7: Taking a backup of the Samba configuration file
The Samba configuration file is in /etc/samba/smb.conf. If you look at the configuration file, then you can find that there are pre-configured settings that explain different configuration directives to supervise you.
Lastly, this is a good practice to take a backup copy of the configuration file. The below command will help you to copy a backup file. Also, preserve the SELinux context.
sudo cp --preserve=context /etc/samba/smb.conf /etc/samba/smb.conf.bak
Setting Samba for Anonymous directory share
Step 8: Creating the anonymous share directory
Firstly, you have to create an anonymous share directory. Also, you have to set the permission for this directory.
For example, I’m creating a directory in / partition with the name of samba/anonymous-share. And, I will set the permission 0775 and ownership to nobody. So, use the below set of commands to fulfill the task.
sudo mkdir -p /samba/anonymous-share
sudo mkdir -p /samba/anonymous-share
sudo chown -R nobody:nobody /samba/anonymous-share
Secondly, we have created the anonymous-share directory. So, now we have to change the SELinux context for this shared directory. Use the below command to change the SELinux context.
sudo chcon -t samba_share_t /samba/anonymous-share

Step: 9: Configuring the Samba server for anonymous share directory
Firstly, lets’ open the Samba configuration file. And, modify/add the below lines. In the first section global, modify it and make changes as below. So, to open this configuration file, I’m using the vim editors but you can use it as per your choice.
sudo vim /etc/samba/smb.conf
Add the below lines
[global] workgroup = WORKGROUP netbios name = centos security = user
Also, add the below lines in the last of the configuration file.
[Anonymous] comment = Anonymous Samba File Share path = /samba/anonymous-share public = yes browsable =yes writable = yes guest ok = yes read only = no force user = nobody
Note: you can change the above lines if you want to allow for anonymous writing or not.
Secondly, you can verify the Samba configuration file using the below command.
testparm
Also, If you want to see all the configurations then you can press the Enter key. You can see this in the below picture.

Lastly, after making the changes, restart the Samba services.
sudo systemctl restart smb nmb
Step 10: Testing anonymous share
So, this is the time to check our anonymous file share on the Windows machine.
- Press Windows key + r
- It will bring a run box.
- Type there your machine hostname or IP address in the below format
- If you are typing hostname then it will be like \\hostname
- And, if you are using an IP address then it will be like \\IP_address for example, \\192.168.43.20

- So, hit Enter key. And it will bring the anonymous directory. You can try to create some files and verify them at your Samba server end.

Setting Samba for Secure file sharing
Step 11: Creating a samba group
You have to create a group. And after creating the group, you can add the users in that group, and also you can set the password for each user. So, let’s create it. You can follow the below commands.
Firstly, creating a group with the name sambagroup
sudo groupadd sambagroup
Secondly, adding a user sahil in sambagroup
sudo usermod -aG sambagroup sahil
Lastly, create a Samba password for the user sahil using the following command
sudo smbpasswd -a sahil
Step 12: Creating a Samba directory for share secure
So, now create a directory where you can keep the shared files and also give permission as per your choice. Also, you have to change the SELinux context.
sudo mkdir -p /samba/secure
sudo chmod -R 0770 /samba/secure
sudo chown -R root:sambagroup /samba/secure
sudo chcon -t samba_share_t /samba/secure
As a result, you can see in the below picture.

Step 13: Configuring the Samba server for secure share directory
Firstly, open the Samba configuration file. And, add the below lines. So, to open this configuration file, I’m using the vim editors but you can use it as per your choice.
sudo vim /etc/samba/smb.conf
Add the below lines
[Secure] comment = Secure File Server Share path = /samba/secure valid users = @sambagroup guest ok = no writable = yes browsable = yes
Secondly, you can verify the Samba configuration file using the below command.
testparm
Also, If you want to see all the configurations then you can press the Enter key. You can see this in the below picture.

Lastly, after making the changes, restart the Samba services.
sudo systemctl restart smb nmb
Step 14: Testing the secure share directory
So, this is the time to check our secure directory share on the Windows machine.
- Press Windows key + r
- It will bring a run box.
- Type there your machine hostname or IP address in the below format
- If you are typing hostname then it will be like \\hostname
- And, if you are using an IP address then it will be like \\IP_address for example, \\192.168.43.20

- So, hit Enter key. And it will bring the box to enter the credentials. So, go ahead and put the username and password as we have created above in Step 11.

- After entering the username and password, if it is correct then you will get the secure directory window and you can test by creating some files in it.

Step 15: Managing Samba Services
There are some commands to manage samba services like start, stop, restart, enable, and disable.
Firstly, if you want to start the service then you can use the command (I’m using smb and nmb both services once but you can also use it separately.)
sudo systemctl start smb nmb
To stop the services
sudo systemctl stop smb nmb
Also, to check if it is enabled on startup or not.
sudo systemctl is-enabled smb nmb
If it is not enabled on startup then you can use the below command to start it on machine startup
sudo systemctl enable smb nmb
Conclusion
In this tutorial, you learn to install and basic configuration of the Samba server. So, that’s it about install samba server. I hope, you understand but if you have any questions, you can ask in the comment section.
| install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server | install samba server |
For further reading about Samba, you can find it useful.
- Also, you can read What is Samba from the Samba page
- How to set up NFS server on CentOS/RHEL 7
- About Samba from Wikipedia
Really enjoyed this blog. Much thanks again. Really Cool.
Permainan setuju untuk bermain bandarq online ini.