02.03.2026

Set Up Samba on CentOS: Install, Configure Shares, Users, SELinux, Firewall

Intro

Samba is an open-source implementation of the SMB protocol used for file and printer sharing in Windows networks. It lets you publish folders on a CentOS server and grant controlled access to Windows, Linux, and macOS clients using authentication and permissions. In this guide, you’ll install Samba, create a secure share, configure smb.conf, add users, and make the setup actually work on CentOS by handling firewall rules and SELinux contexts.

Install Samba

Initial, deploy programs by inserting:

sudo yum install samba samba-client samba-common

Screenshot №1. Install samba packages

Making shared catalogs

Making catalogs for file sharing is the next process.
Do it:

sudo mkdir /home/username/share1

Operating system support creation multiple directories for different users or groups.

Screenshot №2. Creating new shared folder

Configuration

Afterward, it is necessary to modify config file /etc/samba/smb.conf. Perfom:

sudo nano /etc/samba/smb.conf

That file contains many lines of code.
For application to start correctly, let s edit some of them.

Screenshot №3. Default settings of smb.conf

Access settings

Access settings must be configured by adding the lines:

[share1]
path = /home/username/share1
valid users = username
read only = no

Screenshot №4. Edit smb.conf

Creating Users

To create Samba users,  perform:
Create user in OS:

adduser username

Then set password in smb:

sudo smbpasswd -a username

Screenshot №5. Add new user to smb.conf

Restart Samba

Finally, we restart the Samba service to apply the settings by typing:

sudo systemctl restart smb

You can now try to connect to shared folders from another computer on the network using the username and password you created earlier.

Screenshot №6. Restart smb service

Conclusion

Samba is a practical way to enable file (and optionally printer) sharing in mixed Windows/Linux networks using SMB with authentication and permissions. In this guide, you installed Samba on CentOS, created a share, configured smb.conf, added a Samba user, and restarted services to apply changes.
To keep sharing reliable and secure, don’t skip the “CentOS specifics”: allow the Samba service in firewalld, set proper SELinux contexts for shared folders, and harden the server by requiring modern SMB protocols (SMB2+).

You may be also interested in

FAQ: Setting Up Samba on CentOS

Cheatsheet table

Samba on CentOS — Quick Command Cheat Sheet
Task Command Notes
Install Samba
sudo yum install -y samba samba-client samba-common samba-common-tools
Installs server + client utilities
Create share folder
sudo mkdir -p /home/username/share1
Use a real username/path
Set ownership
sudo chown -R username:username /home/username/share1
Ensure the user can read/write
Install SELinux tools
sudo yum install -y policycoreutils-python-utils
Needed for semanage
SELinux: allow share path
sudo semanage fcontext -a -t samba_share_t "/home/username/share1(/.*)?"
Makes it persist across reboots
Apply SELinux context
sudo restorecon -Rv /home/username/share1
Fixes “works in config but denied” issues
Edit Samba config
sudo nano /etc/samba/smb.conf
Add share section + (optional) hardening
Validate config
testparm
Catches syntax errors before restart
Create OS user
sudo adduser username
Samba users map to Linux users
Add Samba user + password
sudo smbpasswd -a username
Creates SMB password for login
Enable & start services
sudo systemctl enable --now smb
sudo systemctl enable --now nmb
nmb is useful for NetBIOS name resolution
Restart Samba
sudo systemctl restart smb
Run after config changes
Open firewall for Samba
sudo firewall-cmd --permanent --add-service=samba
sudo firewall-cmd --reload
Opens 137–139 + 445 as a service
Check service status
systemctl status smb
Should show active/running
Test shares locally
smbclient -L localhost -U username
Lists shares as the user
Connect from Windows
\\SERVER_IP\share1
Use Samba username + password