Samba implements the SMB/CIFS protocol on Linux, enabling RHEL 8 servers to share files with Windows, macOS, and other Linux clients over a local network. Unlike NFS, which is Linux-native, Samba is specifically designed for cross-platform interoperability, making it the go-to choice in mixed-OS environments. This tutorial covers installing Samba, creating a shared directory with a properly configured smb.conf, adding Samba users, enabling the service and firewall rules, applying the correct SELinux context, and testing the share from a client. All commands require root or sudo access on RHEL 8.

Prerequisites

  • RHEL 8 server with root or sudo access
  • A local Linux or Windows client for testing
  • A user account on the server to be given Samba access
  • SELinux in enforcing mode (default on RHEL 8)
  • Network connectivity between server and client

Step 1 — Install Samba Packages

RHEL 8 splits Samba into several packages. Install the main samba server, samba-client for testing tools like smbclient, and samba-common which provides shared configuration utilities and the smb.conf template.

dnf install -y samba samba-client samba-common

# Verify installation
rpm -q samba samba-client samba-common

Step 2 — Create the Shared Directory

Create the directory you want to share and assign ownership to the user who will access it. This example uses a system user named sambauser; adjust the username to match your environment. Permissions should allow the intended user to read and write while restricting others.

# Create a dedicated user if needed
useradd sambauser

# Create the shared directory
mkdir -p /srv/samba/shared
chown sambauser:sambauser /srv/samba/shared
chmod 0770 /srv/samba/shared

ls -ld /srv/samba/shared

Step 3 — Configure smb.conf

The Samba configuration file is /etc/samba/smb.conf. The [global] section sets site-wide parameters; individual share stanzas define what is exported. Back up the original file before editing, then add your share definition.

cp /etc/samba/smb.conf /etc/samba/smb.conf.bak

# Append the global workgroup setting and share stanza
cat >> /etc/samba/smb.conf << 'EOF'

[global]
    workgroup = WORKGROUP
    server string = RHEL8 Samba Server
    security = user
    map to guest = Bad User

[shared]
    path = /srv/samba/shared
    valid users = sambauser
    read only = no
    browseable = yes
    create mask = 0660
    directory mask = 0770
EOF

# Validate the configuration
testparm

Run testparm to check for syntax errors before restarting Samba. It prints a summary of active configuration values and warns about deprecated or conflicting directives.

Step 4 — Add a Samba User and Enable Services

Samba maintains its own password database separate from the system’s /etc/shadow. Use smbpasswd -a to register the system user in the Samba database and set a Samba-specific password. Then enable and start both smb and nmb services.

# Set the Samba password for sambauser
smbpasswd -a sambauser

# Enable and start the Samba daemons
systemctl enable --now smb nmb
systemctl status smb nmb

Step 5 — Open the Firewall for Samba

Add the predefined samba firewalld service, which opens TCP ports 139 and 445 (SMB) and UDP ports 137 and 138 (NetBIOS name service). Apply the change permanently and reload.

firewall-cmd --permanent --add-service=samba
firewall-cmd --reload
firewall-cmd --list-services

Step 6 — Apply SELinux Context and Booleans

On a RHEL 8 system with SELinux enforcing, Samba will be blocked from accessing directories unless the correct SELinux type is applied. Use chcon for an immediate context change and semanage fcontext plus restorecon to make it survive a relabel. The samba_export_all_rw boolean allows Samba to share any directory, not just those explicitly labeled.

# Apply the samba_share_t context to the shared directory
chcon -Rt samba_share_t /srv/samba/shared

# Make the context persistent across relabels
semanage fcontext -a -t samba_share_t '/srv/samba/shared(/.*)?'
restorecon -Rv /srv/samba/shared

# Enable the SELinux boolean for full read-write sharing
setsebool -P samba_export_all_rw on

# Verify the context
ls -lZ /srv/samba/shared

Conclusion

You now have a fully functional Samba file server on RHEL 8 that is accessible from Windows, macOS, and Linux clients. You configured smb.conf with a named share, registered a Samba user, opened the firewall, and resolved SELinux denials using the correct file context and boolean. Samba’s flexible configuration supports advanced scenarios such as Active Directory domain membership, home directory sharing with the [homes] stanza, and printer sharing — all built on the same foundation you established here.

Next steps: How to Set Up NFS File Sharing on RHEL 8, How to Set Up Software RAID with mdadm on RHEL 8, and How to Configure LVM on RHEL 8.