How to Configure Samba Server and Client in Linux for Secure File Sharing

Learn how to configure Samba server and client in Linux for secure file sharing. Step-by-step guide with installation, configuration, firewall, SELinux, and troubleshooting.
 
Introduction
Samba is one of the most widely used file-sharing solutions in Linux environments. It enables Linux systems to share files, directories, and printers with other Linux, Windows, and macOS devices using the Server Message Block (SMB) protocol. Because Windows natively supports SMB protocol, Samba is the preferred solution for creating file servers in mixed operating system environments.

In this step by step guide, you will learn how to install, configure, secure and verify both the Samba server and Samba client on Rocky Linux, AlmaLinux, RHEL, Ubuntu and Debian systems. This comprehensive guide follows production best practices while remaining easy enough for beginners to understand it.

If you're new to Linux, start with our What is Linux? guide before configuring network file sharing - https://www.seeklinux.net/2025/04/what-is-linux.html.

What You Will Learn
In this tutorial, you will learn how to:
  • Install Samba server and client packages on Linux systems
  • Configure a Samba shared directory for secure file sharing 
  • Manage Samba users and authentication
  • Assign Linux file permissions for Samba shares
  • Allow Samba traffic through the firewall
  • Configure SELinux for Samba file sharing on RHEL based systems
  • Mount Samba shares from Linux clients
  • Configure persistent Samba mounts using the /etc/fstab file
  • Verify Samba configuration using built-in Linux tools 
  • Troubleshoot common Samba issues
  • Apply Samba security best practices for production environments
Why Use Samba?
Samba is an excellent choice when you need to share files between Linux and Windows systems. Unlike NFS, which is primarily designed for Linux to Linux communication and Samba provides seamless compatibility with Microsoft Windows while also supporting Linux and macOS clients.

Some common use cases:
  •  Sharing files between Linux and Windows computers
  •  Creating centralized file servers for offices and organizations
  •  Providing shared storage for multiple users
  •  Sharing home directories across a network
  •  Keep project files on central location for development teams
  •  Integrating Linux file servers with Windows Active Directory environments
  •  Sharing printers between Linux and Windows systems
  •  Why System Administrators Choose Samba
What Is Samba?
Samba is an open source software suite that enables file and printer sharing between Linux, Windows and macOS systems. It implements the Server Message Block (SMB) protocol, allowing computers on the same network to securely access shared files and resources regardless of their operating system.

In simple terms, Samba allows a Linux server to behave like a Windows file server. Once configured, authorized users can access shared folders, transfer files, collaborate on documents and use shared printers across the network.

Samba is mostly used in homes, educational institutions, and enterprise environments because it provides reliable cross platform file sharing while supporting user authentication, access control and integration with Microsoft Active Directory.

Mostly Linux services communicate only with other Linux systems but Samba is specifically designed to provide seamless interconnectivity between different operating systems.

How Samba Works
Samba operates on client-server architecture
  •  The Samba Server hosts one or more shared directories
  •  The Samba Client accesses shared resources using the SMB protocol
  •  User’s authentication done with valid credentials before accessing protected files
  •  The Linux file system permissions and Samba configuration together determine who can view, modify or create files
The basic communication process is:
  1.   A client requests permission to access a shared folder
  2.  The Samba server authenticates the user
  3.  The server verifies Linux and Samba permissions
  4.  The requested files are shared over the network
  5.  The client reads or writes data based on the assigned permissions
 This process is transparent to users, making Samba an ideal solution for organizations where Linux and Windows systems need to work together.

Key Components of Samba
Understanding the main Samba components helps simplify administration and troubleshooting.
🧩 Component 📝 Description
smbd Provides file and printer sharing services and handles client authentication.
nmbd Provides NetBIOS name resolution for legacy networks. Modern environments typically rely on DNS instead.
winbindd Integrates Linux systems with Microsoft Active Directory (AD) for centralized user and group authentication.
smb.conf The primary Samba configuration file located at /etc/samba/smb.conf, used to define shared folders, authentication, permissions, and other Samba settings.
Where Is Samba Commonly Used?
Samba is suitable for many environments, including:
  • Share files between Windows laptops, Linux desktops and media devices
  • Provide centralized storage for employees while controlling access through user accounts and permissions
  • Allow students and staff to securely access shared learning materials from different operating systems
  • Used to join Microsoft Active Directory authentication on Linux servers to enable centralized identity control and secure file sharing
  • Manage shared directories to store source code, documentation, backups and project files for multi-developer access
Advantages of Samba
Samba offers several benefits that make it one of the most popular Linux file-sharing solutions.
  • Cross-platform compatibility with Windows, Linux and macOS
  • Secure user authentication
  • Fine-grained access control
  • Integration with Active Directory
  • Support for encrypted SMB communication
  • Reliable file and printer sharing
  • Open-source and free to use
  • Suitable for home labs, businesses and enterprise environments
Limitations of Samba
Although Samba is extremely versatile, it is not always the best choice. Some limitations include:
  • Slightly more complex configuration than NFS
  • Low performance than NFS in Linux only environments
  • Additional authentication management
  • More services to administer and troubleshoot
If your environment consists exclusively of Linux systems then NFS is the better choice because it offers simple configuration and low overhead.

Administrator Tip: For windows authentication implement samba. If your environment consists entirely of Linux servers and workstations then NFS is usually faster and easier to manage.

Samba Architecture
Samba architecture diagram showing a Linux Samba server connected to Linux, Windows, and macOS clients using the SMB protocol for secure file sharing.
Before configuring Samba, it's helpful to understand how it works behind the scenes. Samba operates on client-server architecture where a Linux server hosts shared resources and client systems connect to access those resources over the network using the SMB (Server Message Block) protocol.

Samba is built to provide seamless file sharing between Linux, Windows and macOS systems. This bridge the gap between different operating system using the native networking language.

In a typical deployment, the Samba server stores shared files and directories and authenticates client computers before accessing those shared files and directories.

Components of a Samba Environment
A standard Samba deployment consists of several components.
🧩 Component 📝 Purpose
Samba Server Hosts shared directories and manages client authentication and access to shared resources.
Shared Directory Stores files and folders that are made available to authorized users over the network.
Samba Client Connects to the Samba server to browse, access, and manage shared files and printers.
SMB Protocol Transfers files, folders, and printer data securely between the Samba server and client systems.
Linux File Permissions Control user and group access to shared files at the operating system level.
Samba Configuration Defines shared folders, authentication methods, and access permissions in the /etc/samba/smb.conf configuration file.
Default Ports Used by Samba
Samba communicates over well-known network ports.
🌐 Service Protocol Port 📝 Purpose
SMB TCP 445 Provides file and printer sharing between the Samba server and clients. This is the recommended port for modern SMB communication.
NetBIOS Name Service UDP 137 Provides legacy NetBIOS name resolution for older Windows and SMB environments.
NetBIOS Datagram Service UDP 138 Supports legacy browsing and datagram-based communication on NetBIOS networks.
NetBIOS Session Service TCP 139 Provides legacy SMB session communication for older clients that do not use direct SMB over TCP.
Production Note: latest Samba deployments primarily listen on TCP port 445. Ports 137–139 are mainly required for compatibility with older Windows systems.

Authentication Flow
A simplified authentication process looks like this:Samba authentication flow diagram showing a client sending credentials to the Samba server, authentication, Linux file permission checks, and access to the shared directory.
This layered approach improves security in two ways one is by ensuring that users must pass the Samba authentication and secondly Linux permission checks before accessing shared data.

Administrator Tip: Store shared data in dedicated directories such as /srv/samba/share instead of sharing on system directories like /etc, /usr or /home. This improves security, simplifies backups and makes permission management easier.

Samba vs NFS
Both Samba and NFS (Network FileSystem) are popular file-sharing solutions used in Linux environments. Although they serve a similar purpose but they are designed for different use cases and network environments.

The biggest difference is that Samba is designed for cross platform file sharing, allowing Linux, Windows and macOS systems to access shared files. In contrast, NFS is primarily designed for Linux to Linux file sharing, making it a better choice for Linux-only environments.

Choosing the right solution depends on your operating systems, security requirements, performance expectations and administrative needs.

When Should You Use Samba?
Samba is the better choice when you have multiple operating systems in your network.
Typical use cases include:
  • Sharing files between Linux and Windows computers
  • Office environments with Windows workstations
  • Home networks with Windows and Linux devices
  • Active Directory integration
  • Shared departmental folders
  • Printer sharing across different operating systems
If Windows users need access to shared files and Samba is almost always the recommended solution.

When Should You Use NFS?
NFS is generally the better option when every system in the environment runs Linux or UNIX operating system.
Common use cases include:
  • Linux application servers
  • Virtualization hosts
  • Kubernetes worker nodes
  • Shared Linux storage
  • Backup repositories
  • High-performance computing (HPC) clusters
Because NFS has low protocol overhead than SMB so it often delivers better performance in Linux only environments.

Prerequisites
Before configuring a Samba server and client, ensure that your systems meet the following requirements. Completing these prerequisites will help to avoid common installation and connectivity issues later in the tutorial.

This comprehensive guide used one Linux server and one Linux client for this samba configuration. However, the same steps can be applied to multiple clients in production environments.

Before configuring Samba, ensure your server has a static IP address by following our How to Configure Hostname and Static IP Address in Linux guide - https://www.seeklinux.net/2026/06/how-to-configure-hostname-static-ip.html.

Server Requirements
Before installing Samba verify that the server meets the following requirements.
  • A supported Linux distribution
  • Root or sudo privileges
  • A static IP address
  • Network connectivity to client systems
  • Firewall access for Samba services
  • SELinux configured appropriately (RHEL-based systems)
  • Required Samba packages installed
Using a static IP address is recommended because clients will connect to the Samba server using its network address.

Client Requirements
The client system should meet these requirements.
  • A supported Linux distribution
  • Network connectivity to the Samba server
  • Root or sudo privileges
  • Samba client utilities installed
  • Permission to access the shared directory
Linux, Windows and macOS systems can all connect to a properly configured Samba server.

Administrator Tip: Use meaningful hostnames such as samba server and samba client rather using generic names like server01. Clear hostnames make administration, troubleshooting and documentation much easier.

Best Practice: Assign a static IP address to your Samba server. Dynamic IP addresses obtained through DHCP can change over time, causing clients to lose access to shared resources.

Install Samba
Before configuring shared folders you must install the required Samba packages on the Linux server. The installation process differs slightly between RHEL based and Debian based distributions, but the overall configuration remains the same. This guide covers installation both on RHEL and Ubuntu.

Install Samba on Rocky Linux, AlmaLinux and RHEL
Update your system package repository before installing the required packages.
sudo dnf update -yTerminal showing the dnf update command updating packages on a Red Hat Enterprise Linux, Rocky Linux, AlmaLinux, or Fedora system.

Updating the package repository ensures that the latest versions of Samba and its dependencies are installed. Next, install the Samba package.
sudo dnf install samba samba-client -yLinux terminal showing the installation of Samba and samba-client packages using the DNF package manager for SMB file sharing.

Package Explanation
📦 Package 📝 Description
samba Installs the Samba server along with the required services for file and printer sharing on Linux systems.
samba-client Provides client-side utilities such as smbclient for browsing, testing, and accessing Samba shares.
Verify Installation
After installation, verify that the packages were installed successfully.
rpm -qa | grep sambaLinux terminal verifying the Samba installation by checking the installed Samba package version on a Linux server.

Note: The exact package version may vary depending on your Linux distribution and installed updates.

Install Samba on Ubuntu and Debian
First, update the APT package index before installing the actual samba packages.
sudo apt update -yLinux package update using the dnf update command to install security patches and software updates.

Next, install the required Samba packages
sudo apt install samba smbclient -yLinux terminal showing the sudo apt install samba samba-client -y command to install the Samba server and client packages on Ubuntu or Debian.

Verify Installation
Verify that the packages have been installed.
dpkg -l | grep sambaLinux terminal verifying the Samba installation using the dpkg -l | grep samba command on an Ubuntu or Debian system.

Verify the Samba Version
Before continuing, verify the installed Samba version.
smbd --versionLinux terminal displaying the installed Samba version using the smbd --version command to verify a successful Samba installation.

This confirms that Samba has been installed successfully.

Verify the Samba Configuration File
The main Samba configuration file is located at /etc/samba/smb.conf. Confirm that the configuration file exists.
ls -l /etc/samba/smb.confLinux terminal displaying the ls -l /etc/samba/smb.conf command to verify the Samba configuration file and its permissions.

Do not edit the configuration file yet because Configuration will be covered in the next section.

Verify Samba Services
Before enabling the services verify that the required service files are available.

On RHEL based systems:
systemctl list-unit-files | grep smbLinux terminal displaying the systemctl list-unit-files | grep smb command to verify that the Samba services are installed and available on the system.

On Ubuntu and Debian:
systemctl list-unit-files | grep smbdLinux terminal displaying the systemctl list-unit-files | grep smbd command to verify that the Samba daemon (smbd) service is installed and available on the system.

These services will be started after the server configuration is complete.

Configure the Samba Server
After installing Samba, the next step is to configure the server. This involves creating a shared directory, assigning the appropriate Linux permissions, configuring the Samba share and validating the configuration before starting the Samba services.

By following these steps, you'll create a secure file share that authorized users can access from Linux, Windows and macOS clients.

Create a Shared Directory
First, create the directory that will be shared with users. For this tutorial, we'll create a directory named share under /srv/samba, which is the recommended location for Samba shared data.
sudo mkdir -p /srv/samba/shareLinux terminal creating a shared directory for Samba using the sudo mkdir -p /srv/samba/share command before configuring file sharing.

Understanding Linux permissions is important before sharing directories. See our Linux Directory Structure Explained guide - https://www.seeklinux.net/2025/06/linux-directory-structure-and-file.html.

Why use /srv/samba/share?
The /srv directory is intended for data served by network services. Storing Samba shares here keeps shared data separate from system files and follows the LinuxFilesystem Hierarchy Standard (FHS).

Verify the Directory
Verify that the directory has been created successfully.
ls -ld /srv/samba/shareLinux terminal displaying the ls -ld /srv/samba/share command to verify the Samba shared directory, ownership, and permissions.

Create a Test File
Create a sample file that can later be accessed from the client.
echo "Welcome to SeekLinux Samba Server" | sudo tee /srv/samba/share/test.txtLinux terminal creating a test file in the Samba shared directory to verify successful file sharing and access.

Verify the Test File
ls -l /srv/samba/shareLinux terminal verifying the test file in the Samba shared directory to confirm that the shared folder is configured correctly.

Configure Linux Permissions
Linux permissions determine who can access files before Samba permissions are applied. Change the ownership of the shared directory.
sudo chown -R root:root /srv/samba/shareLinux terminal changing the ownership of the Samba shared directory to root:root using the sudo chown -R command for secure file sharing.

Assign appropriate permissions to share directory
sudo chmod -R 755 /srv/samba/shareLinux terminal setting 755 permissions on the Samba shared directory using the sudo chmod -R command to configure secure file sharing.

Verify Permissions
ls -ld /srv/samba/shareLinux terminal displaying the ls -ld /srv/samba/share command to verify the ownership and 755 permissions of the Samba shared directory.

Note: Later, you can assign ownership to a dedicated Samba user or group depending on your environment.

Back Up the Samba Configuration File
Before making changes, create a backup of the default configuration file.
sudo cp /etc/samba/smb.conf /etc/samba/smb.conf.bakLinux terminal creating a backup of the Samba configuration file using the cp command before modifying smb.conf.

Verify the backupLinux terminal verifying the backup of the Samba configuration file by listing smb.conf and smb.conf.bak in the /etc/samba directory.

Edit the Samba Configuration File
Open the Samba configuration file with your favorite editor.

sudo vi /etc/samba/smb.conf
Scroll to the bottom of the file and add the following share definition.Linux terminal opening the Samba configuration file (/etc/samba/smb.conf) with the vi editor to configure Samba file sharing.

Understanding the Configuration
⚙️ Parameter 📝 Description
path Specifies the directory on the Linux server that will be shared with clients.
browseable Controls whether the shared folder appears when clients browse available Samba shares.
read only When set to no, authorized users can create, modify, and delete files in the shared directory.
writable Allows users with permission to create, edit, and delete files in the shared directory.
guest ok When set to no, users must authenticate with a valid Samba username and password before accessing the share.
valid users Restricts access to the specified Samba users or groups.
create mask Defines the default file permissions assigned to newly created files.
directory mask Defines the default directory permissions assigned to newly created folders.
Create a Samba User
Samba users must already exist as Linux users. Create a Linux user.
sudo useradd sambauserLinux terminal creating a new Samba user account with the sudo useradd sambauser command before configuring Samba authentication.

If you're unfamiliar with creating Linux users, read our Managing Users and Groups in Linux tutorial - https://www.seeklinux.net/2025/08/managing-users-and-groups-in-linux.html.

Assign a password
sudo passwd sambauserLinux terminal setting a password for the sambauser account using the sudo passwd command before configuring Samba authentication.

Now add the user to the Samba database
sudo smbpasswd -a sambauserLinux terminal adding the sambauser account to the Samba user database using the sudo smbpasswd -a command for SMB authentication.

Enable the user
sudo smbpasswd -e sambauserLinux terminal enabling the sambauser account in the Samba user database using the sudo smbpasswd -e command for SMB authentication.

Verify the Samba User
This command will display all Samba users.
sudo pdbedit -LLinux terminal listing all Samba users in the Samba user database using the sudo pdbedit -L command to verify user accounts.

Validate the Samba Configuration
Before starting the service, always verify the configuration.
testparm
Linux terminal validating the Samba configuration file using the testparm command to check for syntax errors before starting Samba services.

If any syntax errors exist, correct them before continuing.

Start and Enable Samba Services
After configuring the Samba server, you must start the Samba services so that client systems can connect to the shared resources. It is also recommended to enable these services so they start automatically whenever the server reboots.

Start Samba Services on Rocky Linux, AlmaLinux and RHEL
Start these both Samba services.

sudo systemctl enable --now smb
sudo systemctl enable --now nmbLinux terminal enabling and starting the smb and nmb Samba services using the systemctl enable --now command for SMB file sharing.

The enable --now option performs two actions:
  • Starts the service immediately
  • Enables the service to start automatically during system boot
Verify Service Status
Check that both services are running.
sudo systemctl status smbLinux terminal displaying the status of the smb service using the sudo systemctl status smb command to verify that the Samba server is running successfully.

Start Samba Services on Ubuntu and Debian
On Debian based systems, the service names are slightly different.

Start services Ubuntu
sudo systemctl enable --now smbdLinux terminal enabling and starting the smbd service using the sudo systemctl enable --now smbd command for Samba file sharing.

Verify Service Status
sudo systemctl status smbdLinux terminal displaying the status of the smbd service using the sudo systemctl status smbd command to verify that the Samba server is running successfully.

Verify Samba Is Listening
Use the following command to verify that Samba is listening on the expected network ports.
ss -ltunp | grep smbLinux terminal verifying that Samba services are listening on network ports using the ss -ltunp | grep smb command.

This confirms that the Samba server is ready to accept client connections.

Verify Running Services
You can also verify the running processes.
ps -ef | grep smbdLinux terminal displaying the ps -ef | grep smbd command to verify that the Samba daemon (smbd) process is running successfully.

Verify Boot Configuration
Make sure that Samba will start automatically after a reboot. For RHEL based systems:
systemctl is-enabled smbLinux terminal checking whether the Samba smb service is enabled at boot using the systemctl is-enabled smb command.

For Ubuntu/Debian:
systemctl is-enabled smbdLinux terminal checking whether the smbd service is enabled at boot using the systemctl is-enabled smbd command.

Restart Samba Service After Configuration Changes
Whenever you modify the smb.conf file, restart the Samba service to apply the changes.

Rocky Linux / AlmaLinux / RHEL
sudo systemctl restart smbLinux terminal restarting the Samba smb service using the sudo systemctl restart smb command to apply configuration changes.

Ubuntu / Debian
sudo systemctl restart smbdLinux terminal restarting the smbd service using the sudo systemctl restart smbd command to apply Samba configuration changes.

Best Practice: Always run the testparm command before restarting Samba server to validate the configuration file and avoid service startup failures.

Troubleshooting Tip: If the service does not start successfully, check the logs.

Rocky Linux / RHEL
journalctl -xeu smbLinux terminal displaying Samba smb service logs using the journalctl -xeu smb command to troubleshoot startup and configuration issues.

Ubuntu / Debian
journalctl -xeu smbdLinux terminal displaying smbd service logs using the journalctl -xeu smbd command to troubleshoot Samba server startup and configuration issues.

Review the logs for configuration errors, permission problems or missing dependencies.

Configure the Firewall
If your Linux server is running a firewall, you must allow Samba traffic before clients start accessing shared folders. Even if the Samba services are running correctly, clients will be unable to connect if the required firewall ports are blocked.

Note: Latest Samba deployments primarily use TCP port 445. Ports 137–139 are mainly required for compatibility with older Windows clients.

If networking concepts are new to you, our Linux Basic Networking for Beginners guide explains IP addressing, gateways, and connectivity - https://www.seeklinux.net/2025/11/linux-basic-networking-for-beginners.html.

Configure the Firewall on Rocky Linux, AlmaLinux and RHEL
Allow the Samba service through firewalld.
sudo firewall-cmd --permanent --add-service=sambaLinux terminal allowing Samba through the firewall using the sudo firewall-cmd --permanent --add-service=samba command for SMB file sharing.

Reload the firewall configuration
sudo firewall-cmd --reloadVerify the Firewall RuleLinux terminal reloading Firewalld using the sudo firewall-cmd --reload command to apply Samba firewall configuration changes.

Verify the Firewall Rule
Check that the Samba service has been added successfully.
sudo firewall-cmd --list-servicesLinux terminal verifying allowed firewall services using the sudo firewall-cmd --list-services command to confirm that Samba is enabled in Firewalld.

The presence of samba confirms that the firewall is allowing SMB traffic.

Configure the Firewall on Ubuntu and Debian
If your system uses UFW (Uncomplicated Firewall), allow Samba traffic with:
sudo ufw allow Samba Linux terminal allowing Samba through the UFW firewall using the sudo ufw allow Samba command to enable SMB file sharing.

Reload the firewall if necessary
sudo ufw reloadLinux terminal reloading the UFW firewall using the sudo ufw reload command to apply Samba firewall configuration changes.

Verify the Firewall Rule
Check the current firewall status.
sudo ufw statusLinux terminal checking the UFW firewall status using the sudo ufw status command to verify that Samba firewall rules are active.

Verify That Samba Ports Are Reachable
After configuring the firewall, verify that Samba is listening on the required ports.
ss -ltunp | grep smbLinux terminal verifying that the Samba service is listening on network ports using the ss -ltunp | grep smb command.

Test Connectivity from the Client
From the client machine, test whether the Samba server is reachable.
ping -c 4 192.168.1.164Linux terminal testing network connectivity to the Samba server using the ping -c 4 192.168.1.164 command before accessing shared folders.

If network connectivity is successful but clients still cannot connect, verify:
  • Samba services are running
  • Firewall rules are configured correctly
  • SELinux settings (RHEL-based systems)
  • The shared directory configuration
Configure SELinux (RHEL Based Systems)
If you are using Rocky Linux, AlmaLinux, CentOS Stream or Red Hat Enterprise Linux (RHEL), SELinux may prevent Samba from accessing shared directories even when the Samba configuration and Linux file permissions are correct.

SELinux provides an additional layer of security by enforcing mandatory access control (MAC) policies. Rather than disabling SELinux, configure the appropriate policies so Samba can access the shared directory securely.

Note: This section applies only to RHEL based Linux distributions. Ubuntu and Debian use AppArmor by default and do not require these SELinux configuration steps.

Check the SELinux Status
Before making any changes, verify whether SELinux is enabled.
getenforce
Linux terminal checking the current SELinux mode using the getenforce command before configuring Samba file sharing.

Possible outputs:
🛡️ SELinux Status 📝 Description
Enforcing SELinux is active and enforces security policies by allowing or denying access based on defined security rules.
Permissive SELinux logs policy violations for auditing purposes but does not block access, making it useful for troubleshooting.
Disabled SELinux is completely disabled and provides no policy enforcement. This mode is not recommended for production systems.
Best Practice: Keep SELinux in Enforcing mode for production systems whenever possible.

Configure the Shared Directory Context
Assign the correct SELinux security context to the Samba shared directory.

sudo semanage fcontext -a -t samba_share_t "/srv/samba/share(/.*)?"

Apply the new SELinux context
sudo restorecon -Rv /srv/samba/shareLinux terminal restoring SELinux security contexts for the Samba shared directory using the sudo restorecon -Rv /srv/samba/share command.

Verify the SELinux Context
Confirm that the correct SELinux context has been applied.
ls -Zd /srv/samba/shareLinux terminal displaying the SELinux security context of the Samba shared directory using the ls -Zd /srv/samba/share command to verify correct SELinux labels.

The samba_share_t context allows the Samba service to access the shared directory securely.

Enable Required SELinux Boolean
If users need read and write access to the shared directory, enable the appropriate SELinux policy.
sudo setsebool -P samba_export_all_rw onLinux terminal enabling the SELinux samba_export_all_rw Boolean using the sudo setsebool -P samba_export_all_rw on command to allow Samba read and write access.

The -P option makes the change persistent across system reboots.

Verify the SELinux Boolean
Check that the policy has been enabled successfully.
getsebool samba_export_all_rwLinux terminal checking the status of the samba_export_all_rw SELinux Boolean using the getsebool samba_export_all_rw command to verify Samba read and write permissions.

Troubleshoot SELinux Access Issues
If Samba cannot access the shared directory, review the SELinux audit logs.
sudo ausearch -m AVCLinux terminal searching SELinux Access Vector Cache (AVC) denial logs using the sudo ausearch -m AVC command to troubleshoot Samba permission issues.

This command displays SELinux access denial (AVC) messages, helping identify permission issues.

Configure the Samba Client
After successfully configuring the Samba server, the next step is to configure the Linux client. The client requires the appropriate SMB utilities to discover available shares, mount the shared directory, and access files stored on the Samba server.

Install Samba Client Packages
Before connecting to the Samba server, install the required utilities on the client system.

Rocky Linux, AlmaLinux, and RHEL
sudo dnf install samba-client cifs-utils -y

Package Explanation
📦 Package 📝 Description
samba-client Provides client-side tools such as smbclient for browsing, testing, and accessing Samba shares from Linux systems.
cifs-utils Provides the mount.cifs utility used to mount Samba (SMB/CIFS) shared directories on Linux systems.
Verify Installation
rpm -qa | grep samba

Verify the CIFS utilities
rpm -qa | grep cifsLinux terminal listing installed CIFS packages using the rpm -qa | grep cifs command to verify that CIFS client utilities are installed on a RHEL-based system.

Ubuntu and Debian
Update the package repository before package installation.
sudo apt updateLinux terminal updating the APT package index using the sudo apt update command before installing Samba on Ubuntu or Debian.

Install the required packages
sudo apt install smbclient cifs-utils -yLinux terminal installing the smbclient and cifs-utils packages using the sudo apt install command to enable Samba client access and SMB share mounting on Ubuntu.

Verify Installation
dpkg -l | grep smbclientLinux terminal verifying the installation of the smbclient package using the dpkg -l | grep smbclient command on Ubuntu or Debian.

Verify the CIFS utilities
dpkg -l | grep cifs-utilsLinux terminal verifying the installation of the cifs-utils package using the dpkg -l | grep cifs-utils command on Ubuntu or Debian.

Discover Available Samba Shares
Before mounting a share, verify that the client can communicate with the Samba server. Run the following command from the client.

smbclient -L //192.168.1.164 -U sambauser
You will be prompted for the Samba password.
Linux terminal listing available Samba shared folders on the server using the smbclient -L //192.168.1.164 -U sambauser command to verify SMB connectivity and user access.

This confirms that the Samba server is reachable and the shared folder is available.

Create a Mount Point
Create a local directory that will serve as the mount point.
sudo mkdir -p /mnt/samba-shareLinux terminal creating the /mnt/samba-share mount point using the sudo mkdir -p /mnt/samba-share command before mounting a Samba (SMB/CIFS) shared folder.

Verify the Directory
ls -ld /mnt/samba-share

Mount the Samba Share
Mount the shared directory using the mount.cifs utility.
sudo mount -t cifs //192.168.1.164/Share /mnt/samba-share -o username=sambauserLinux terminal mounting a Samba (SMB/CIFS) shared folder using the sudo mount -t cifs command with user authentication to access network files.

After entering the password, the shared directory will be mounted on the client.

Verify the Mount
Check that the share has been mounted successfully.
mount | grep cifsLinux terminal verifying that the Samba (SMB/CIFS) shared folder is successfully mounted using the mount | grep cifs command.

If you're comparing Linux file-sharing technologies, see our How to Configure NFS Server and Client in Linux guide to understand when to use Samba versus NFS - https://www.seeklinux.net/2026/06/how-to-configure-nfs-server-and-client.html.

Verify File Access
List the files stored in the shared directory.
ls -l /mnt/samba-shareLinux terminal listing the contents of the mounted Samba (SMB/CIFS) shared folder using the ls -l /mnt/samba-share command to verify successful file access.

Open the test file
cat /mnt/samba-share/test.txtLinux terminal displaying the contents of test.txt from the mounted Samba (SMB/CIFS) shared folder using the cat /mnt/samba-share/test.txt command to verify successful file access.

Test Write Access
Create a new file from the client.
touch /mnt/samba-share/client-test.txtLinux terminal creating client-test.txt in the mounted Samba (SMB/CIFS) shared folder using the touch command to verify write access from the Linux client.

Verify the file
ls -l /mnt/samba-shareLinux terminal listing the contents of the mounted Samba (SMB/CIFS) shared folder using the ls -l /mnt/samba-share command to verify successful read and write access.

Now return to the Samba server and verify that the file exists in the shared directory. The newly created file should be visible, confirming successful read and write access.
ls -l /srv/samba/shareLinux terminal listing the contents of the Samba shared directory using the ls -l /srv/samba/share command to verify that shared files were created successfully.

Configure Automatic Mounting
Mounting a Samba share manually is useful for testing, but the mount is lost after the system reboots. To ensure the shared directory is mounted automatically every time the Linux client starts, add the Samba share to the /etc/fstab file.

Persistent mounting is commonly used on workstations, application servers, backup servers and environments where continuous access to shared files is required.

Note: Before configuring automatic mounting, make sure you have successfully mounted the Samba share manually and verified that it is working correctly.

Create a Credentials File
Storing the Samba username and password directly in the /etc/fstab file is not recommended because it exposes sensitive credentials. Instead, create a dedicated credentials file.

Create the credentials file
sudo vi /etc/samba/samba-credentialsLinux terminal opening the Samba credentials file (/etc/samba/samba-credentials) with the vi editor to securely store the SMB username and password for automatic share mounting.

Add the following content

Save and close the file.

Secure the Credentials File
Restrict access so that only the root user can read it.
sudo chmod 600 /etc/samba/samba-credentialsLinux terminal securing the Samba credentials file using the sudo chmod 600 /etc/samba/samba-credentials command to protect the SMB username and password.

Verify Permissions
ls -l /etc/samba/samba-credentialsLinux terminal verifying the permissions of the Samba credentials file using the ls -l /etc/samba/samba-credentials command to ensure secure SMB authentication.

Only the root user should have read and write permissions.
Configure the /etc/fstab File
Open the file
sudo vi /etc/fstabLinux terminal opening the /etc/fstab file with the vi editor to configure automatic mounting of a Samba (SMB/CIFS) shared folder at system startup.

Add the following entry at the bottom of the file
//192.168.1.164/Share /mnt/samba-share cifs credentials=/etc/samba/samba-credentials,_netdev,iocharset=utf8,vers=3.0 0 0                                                     

Understanding the Mount Options
⚙️ Option 📝 Purpose
credentials= Uses a secure credentials file instead of storing passwords in /etc/fstab.
_netdev Waits until the network is available before mounting the Samba share.
iocharset=utf8 Enables UTF-8 character encoding for filenames.
vers=3.0 Uses SMB version 3.0 for improved security, compatibility, and performance.
Test the Configuration
Before rebooting, verify that the /etc/fstab entry is valid.
sudo mount -aLinux terminal mounting all filesystems from the /etc/fstab file using the sudo mount -a command to verify automatic Samba (SMB/CIFS) share mounting.

If the command completes without errors, the configuration is correct.

Verify the Mount
mount | grep cifsLinux terminal verifying that the Samba (SMB/CIFS) shared folder is mounted successfully using the mount | grep cifs command after configuring automatic mounting.

Verify After a Reboot
Restart the client.

sudo reboot
After logging in again, verify that the share was mounted automatically.

Administrator Tip: Always test the /etc/fstab configuration with mount -a command before rebooting. This helps to identify syntax or configuration errors that avoids correctly mounting the network file shares.

Common Samba Troubleshooting
Even with a correct Samba configuration, you may occasionally encounter connectivity, authentication, or permission issues. Most Samba problems are caused by incorrect configuration, firewall restrictions, Linux file permissions, SELinux policies, or network connectivity.

1. Permission Denied
One of the most common Samba errors is:
nt_status_access_denied

or
Permission denied

Possible Causes
  • Incorrect Linux file permissions
  • Incorrect Samba user permissions
  • Invalid valid user’s configuration
  • SELinux blocking access
  • Incorrect ownership of the shared directory
Solution
Verify Linux permissions.
Verify ownership.
ls -l /srv/samba/share

Verify the Samba user.
sudo pdbedit -L

Verify SELinux.
ls -Zd /srv/samba/share

2. Authentication Failed
Error
nt_status_login_failure

Possible Causes
  • Incorrect username
  • Incorrect password
  • Samba user not created
  • Samba account disabled
Solution
Display Samba users.
sudo pdbedit -L

Reset the password.
sudo smbpasswd sambauser

Enable the account.
sudo smbpasswd -e sambauser

3. Share Not Found

Error
nt_status_bad_network_name

Possible Causes
  • Incorrect share name
  • Typographical error
  • Missing share definition in smb.conf
  • Configuration not reloaded
Solution
Display available shares.
smbclient -L //192.168.1.164 -U sambauser

Validate the configuration.
testparm

Restart Samba service.

RHEL
sudo systemctl restart smb

Ubuntu
sudo systemctl restart smbd

4. Unable to Connect to the Samba Server

Error
Connection refused

Possible Causes
  • Samba service stopped
  • Firewall blocking SMB
  • Incorrect IP address
  • Network connectivity problem
Solution
Verify the service.

RHEL
sudo systemctl status smb

Ubuntu
sudo systemctl status smbd

Verify the firewall.

RHEL
sudo firewall-cmd --list-services

Ubuntu
sudo ufw status

Test connectivity.
ping -c 4 192.168.1.164

5. Cannot Mount Samba Share

Error
mount error(13): Permission denied

Possible Causes
  • Incorrect credentials
  • Missing cifs-utils
  • Wrong share name
  • Firewall issue
Solution
Verify the credentials file.
cat /etc/samba/samba-credentials

Verify package installation.

RHEL
rpm -qa | grep cifs

Ubuntu
dpkg -l | grep cifs-utils

Try mounting manually
sudo mount -t cifs //192.168.1.164/Share /mnt/samba-share -o username=sambauser

6. SELinux Denies Access
If SELinux blocks Samba access, review the audit logs.
sudo ausearch -m AVC

Verify the SELinux context.
ls -Zd /srv/samba/share

Verify the SELinux boolean.
getsebool samba_export_all_rw

7. Configuration Errors
If Samba does not start after editing smb.conf, check the configuration syntax.
testparm

Always correct configuration errors before restarting the service.
8. View Samba Service Logs

Rocky Linux / RHEL
journalctl -xeu smb

Ubuntu / Debian
journalctl -xeu smbd

Review the logs for:
  • Syntax errors
  • Permission problems
  •  Authentication failures
  • Missing directories
  • SELinux denials
9. Verify Open Network Ports
Check that Samba is listening on the required ports.
ss -ltunp | grep smb

Quick Troubleshooting Checklist
Before investigating complex issues, verify the following:
  • Samba packages are installed. Samba services are running
  • Shared directory exists
  • Linux permissions are correct
  • Samba user exists
  • Firewall allows Samba traffic
  • SELinux is configured correctly (RHEL-based systems)
  • testparm reports no configuration errors
  • Client can reach the server
Samba Security Best Practices
Securing a Samba server is just as important as configuring it correctly. An insecured file server can expose sensitive data, allow unauthorized access or become a target for network attacks.

  • Use Strong Passwords
  • Disable Guest Access
  • Restrict Access to Authorized Users
  • Apply the Principle of Least Privilege
  • Use Secure Linux File Permissions
  • Use Dedicated Shared Directories
  • Keep Samba Updated
  • Disable Legacy SMB Protocols
  • Protect the Credentials File
  • Restrict Firewall Access
  • Keep SELinux Enabled (RHEL-Based Systems)
  • Monitor Samba Logs
Frequently Asked Questions (FAQs)

1. What is Samba in Linux?
Samba is an open-source software suite that enables file and printer sharing between Linux, Windows and macOS systems using the SMB (Server Message Block) protocol. It allows a Linux server to function as a file server that can be accessed by different operating systems.

2. What is the difference between Samba and NFS?
Samba is designed for cross platform file sharing and works well with Linux, Windows and macOS. NFS is primarily intended for Linux to Linux file sharing and normally provides better performance in Linux only environments. If your network includes Windows computers then Samba is usually the preferred choice.

3. Which ports does Samba use?
Samba primarily uses the following ports:
  • TCP 445 – SMB file sharing (recommended)
  • TCP 139 – NetBIOS Session Service
  • UDP 137 – NetBIOS Name Service
  • UDP 138 – NetBIOS Datagram Service
Latest Samba deployments mainly use TCP port 445.

4. What is the location of samba configuration file?
The primary Samba configuration file is:
/etc/samba/smb.conf
This file defines shared directories, access permissions, authentication settings and other Samba configuration options.

5. How do I check whether Samba is running?
You can verify the Samba service using:

Linux / RHEL
sudo systemctl status smb

Ubuntu / Debian
sudo systemctl status smbd
A status of active (running) indicates that the Samba service is operating correctly.
In this guide, you learned how to install, configure, secure and verify a Samba server and client on Linux for reliable file sharing. By following these best practices you can create a secure and efficient file sharing environment for Linux, Windows and macOS systems. Regular maintenance, updates and proper access control will help to keep your Samba deployment stable and secure. 

Samba is an excellent choice when you need to share files between Linux and Windows systems. Unlike NFS, which is primarily designed for Linux to Linux communication and Samba provides seamless compatibility with Microsoft Windows while also supporting Linux and macOS clients.

Continue building your Linux administration skills by exploring our guides on Linux Networking, Users & Groups, NFS File Sharing, and other tutorials in the Linux Beginners Guide series on seeklinux.


Author: Aqeel Anwar

SeekLinux Author
SeekLinux Team
Linux Engineers | DevOps | Security Enthusiasts

SeekLinux Team shares practical Linux tutorials, SSL/TLS certificate guides, commands and DevOps solutions. Our goal is to simplify system administration and help you master real-world server and security tasks.

Learn more about us →

Post a Comment

Previous Post Next Post