Samba implements the SMB/CIFS protocol on Linux, enabling seamless file sharing between RHEL 9 servers and Windows clients — as well as other Linux systems. It is the go-to solution for mixed-OS environments where Windows users need to access Linux-hosted files using the same UNC paths and credential prompts they are accustomed to. On RHEL 9, Samba integrates with firewalld and SELinux and requires a few deliberate configuration steps to work correctly. This tutorial walks through a complete Samba server setup, including SELinux contexts and client access from both Windows and Linux.
Prerequisites
- RHEL 9 server with root or sudo access
- A Windows or Linux client on the same network
firewalldand SELinux in enforcing mode (default RHEL 9 state)- A local user account to assign Samba credentials to
Step 1 — Install Samba Packages and Create the Share Directory
Install the samba and samba-client packages, then create the directory that will be shared:
# Install Samba
dnf install -y samba samba-client
# Create the shared directory
mkdir -p /srv/samba/share
chmod 0755 /srv/samba/share
# Optionally set a group for shared write access
groupadd sambagroup
chown root:sambagroup /srv/samba/share
chmod 0775 /srv/samba/share
Step 2 — Configure /etc/samba/smb.conf
The main Samba configuration file is /etc/samba/smb.conf. It has a [global] section for server-wide settings and one or more named share sections. Edit the file to define your share:
[global]
workgroup = WORKGROUP
server string = RHEL9 Samba Server
security = user
passdb backend = tdbsam
log file = /var/log/samba/log.%m
max log size = 50
dns proxy = no
[share]
comment = Shared Files
path = /srv/samba/share
valid users = smbuser
writable = yes
browsable = yes
create mask = 0664
directory mask = 0775
The valid users directive restricts access to listed users. Replace smbuser with your actual username or a group (prefix with @ for groups, e.g., @sambagroup).
Step 3 — Add a Samba User and Test Configuration
Samba maintains its own password database separate from Linux system passwords. The user must already exist as a Linux system user:
# Create the Linux user if it does not exist
useradd -M -s /sbin/nologin smbuser
# Add to sambagroup if using group-based access
usermod -aG sambagroup smbuser
# Set the Samba password (prompts for password)
smbpasswd -a smbuser
# Enable the Samba account
smbpasswd -e smbuser
# Test the configuration for syntax errors
testparm
testparm parses smb.conf and reports any errors or warnings. Always run it after editing the config file before restarting services.
Step 4 — Set SELinux Context and Open the Firewall
SELinux enforces that Samba can only access directories labeled with the samba_share_t context. Without this, Samba will silently fail to serve files even though permissions look correct:
# Apply the correct SELinux context to the share directory
semanage fcontext -a -t samba_share_t '/srv/samba/share(/.*)?'
restorecon -RFv /srv/samba/share
# Verify context was applied
ls -ldZ /srv/samba/share
# Allow Samba through the firewall
firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
If semanage is not available, install it with dnf install -y policycoreutils-python-utils.
Step 5 — Start Samba Services
Samba requires two daemons: smb handles file and print sharing, while nmb handles NetBIOS name resolution for legacy Windows clients:
# Enable and start both Samba daemons
systemctl enable --now smb.service
systemctl enable --now nmb.service
# Confirm they are running
systemctl status smb.service
systemctl status nmb.service
Step 6 — Connect from Windows and Linux Clients
From a Windows client, open File Explorer and enter \192.168.1.100share in the address bar. Enter the Samba username and password when prompted.
From a Linux client, use smbclient to browse or mount with CIFS:
# Install client tools if not present
dnf install -y samba-client cifs-utils
# List shares on the server
smbclient -L //192.168.1.100 -U smbuser
# Connect interactively
smbclient //192.168.1.100/share -U smbuser
# Mount persistently via /etc/fstab
mkdir -p /mnt/samba
echo "//192.168.1.100/share /mnt/samba cifs username=smbuser,password=secret,uid=1000,gid=1000,_netdev 0 0" >> /etc/fstab
# For security, store credentials in a protected file instead
# /etc/samba/credentials.smbuser (chmod 600)
echo "username=smbuser
password=secret" > /etc/samba/credentials.smbuser
chmod 600 /etc/samba/credentials.smbuser
# fstab entry using credentials file
echo "//192.168.1.100/share /mnt/samba cifs credentials=/etc/samba/credentials.smbuser,_netdev 0 0" >> /etc/fstab
mount -a
Conclusion
You have installed and configured Samba on RHEL 9, defined a file share with user-based access control, set the required SELinux context, opened the firewall, and connected to the share from both Windows and Linux clients. The use of a credentials file for CIFS mounts keeps passwords out of /etc/fstab, following security best practices.
Next steps: How to Set Up NFS File Sharing on RHEL 9, How to Configure LVM on RHEL 9, and How to Set Up Software RAID with mdadm on RHEL 9.