Configuring Samba on CentOS 8

One of the most common ways of interacting between linux machines and windows is Samba. Samba is a Suite of programs that allow you to create and access to network drives and shared folders on same or different operating systems. The most common way to use Samba is configured as a file server.

In our today’s tutorial you will learn how to install and configure Samba CentOS 8 for sharing files between Linux and Windows systems. Access to the shared server folder is configured to the first part for any user without requiring a password and a second password request access to a protected shared folder.

Installing samba in CentOS 8

First login to your server as user root. Then use the command given below to install the required packages:

dnf install samba samba-common samba-client-y

By default, all windows computers are using the working group WORKGROUP. You can verify the ownership of your Windows computer to the working group by running the following command:

net config workstation

Configuring samba on CentOS 8

First before configuring rename the Samba configuration file to save a backup. Executes this action with the following command:

mv /etc/samba/smb.conf /etc/samba/smb.conf.default

1. Shared resource with anonymous access

Now on the server, create shared resource where will be stored the files and folders granted to them anonymous. For this you need to create a folder which will be given anonymous access:

mkdir -p /srv/samba/anonymous

Then configure rights and permissions in selinux access this folder by using the following commands:

chmod-R 0755 /srv/samba/anonymous

chown-R nobody:nobody /srv/samba/anonymous

chcon -t samba_share_t /srv/samba/anonymous

Now create a new Samba configuration file with the following command:

nano /etc/samba/smb.conf

Add to the created file the following lines:

workgroup = WORKGROUP
server string = Samba Server %v
netbios name = rhel8
security = user
map to guest = bad user
dns proxy = no

path = /srv/samba/anonymous
browsable =yes
writable = yes
guest ok = yes
read only = no

Check the settings for Samba by running the following command:


Now you need to add the Samba service to the firewall and run it. To do this, run the following command:

firewall-cmd --permanent --add-service=samba

firewall-cmd --reload

Start and add to autostart the Samba service:

systemctl start smb.service
systemctl enable smb.service
systemctl start nmb.service
systemctl enable nmb.service

Now on your windows machine open the line to Run in the menu start or using the shortcut key Win+R. In the open line type the following command and hit OK or Enter:


You will open the network folder is located on your CentOS 8 server is configured for anonymous access.

Now you can add the required files and folders in this folder allowing other users access to them.

Configuring Samba CentOS 8 for anonymous data access is completed.

2. Common resource with private access

To grant access to files and folders to specific users, create a protected folder with Samba. First, create a protected group of users. To do this, run the following command:

groupadd securedgroup

Now add the user to the group securedgroup which will be entrance in a protected folder:

useradd demo -G securedgroup

Now, create a secure shared folder for Samba and add the necessary permissions by running the following commands:

mkdir -p /srv/samba/secured

chmod-R 0770 /srv/samba/secured

chcon -t samba_share_t /srv/samba/secured

chown-R root:securedgroup /srv/samba/secured/

Now add the user to the database and set its password:

smbpasswd-a demo

Add in the Samba configuration file the following lines:

nano /etc/samba/smb.conf

path = /srv/samba/secured
valid users = @securedgroup
guest ok = no
writable = yes
browsable = yes

Then restart Samba with the following command:

systemctl restart smb.service

Now, in order to access protected folder on your CentOS 8 server from your windows machine, open a line to Run from the menu start or using the key combination Win+R and type:


Then click OK or press Enter.

When you try to log in a protected folder, you will have the window with the requirement to enter a user name and password to access the files in a protected folder.

After entering the username and password you will be able to access the secured folder. Now you can add files and folders to share them only with specific users.


In today’s tutorial we told you how to install samba centos 8 and how to install and configure shared folders located on your CentOS 8 server to share files and folders with other users.


(Visited 10 times, 2 visits today)