Serverspace Black Friday
DF
April 4 2025
Updated March 2 2026

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

CentOS Samba

Using another OS?

Select the desired version or distribution.

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
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.

sudo-mkdir-share1
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.

sudo-nano-smb.conf
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
edit-smb.conf
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
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.

sudo-systemctl-restart smb
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

  • Q1: What is Samba used for?
    Samba is open-source software that enables file and printer sharing across Windows, Linux, and other operating systems. It allows devices on the same network to access shared resources securely.
  • Q2: Can I use Samba only with Linux systems?
    No, Samba is cross-platform. It works with Linux, Windows, and macOS, making it ideal for mixed-OS environments.
  • Q3: How do I check if Samba is running on CentOS?
    You can use the command:
    systemctl status smb

    If Samba is active, you will see its status as “running.”

  • Q4: Do I need to create a separate Samba user?
    Yes. Besides creating a system user, you must add the user to Samba with smbpasswd -a username to enable access.
  • Q5: Is Samba secure for file sharing?
    Yes, Samba supports user authentication, encrypted connections, and configurable permissions, which make it secure when properly configured.

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
Vote:
4 out of 5
Аverage rating : 4.7
Rated by: 3
1101 CT Amsterdam The Netherlands, Herikerbergweg 292
+31 20 262-58-98
700 300
ITGLOBAL.COM NL
700 300

You might also like...

We use cookies to make your experience on the Serverspace better. By continuing to browse our website, you agree to our
Use of Cookies and Privacy Policy.