How to Set Up Samba for File Sharing on Linux Servers

What is Samba? Samba is an open-source implementation of the SMB/CIFS protocol that allows Linux and Unix systems to share files with Windows clients, as well as with other Linux machines. With Samba, you can set up a file server that can be accessed by computers on a local network. Prerequisites St

Last updated 30 Nov 2026Also in: Dedicated Servers

What is Samba?

Samba is an open-source implementation of the SMB/CIFS protocol that allows Linux and Unix systems to share files with Windows clients, as well as with other Linux machines. With Samba, you can set up a file server that can be accessed by computers on a local network.

Prerequisites

  1. A Linux server (such as Ubuntu or CentOS) with root or sudo access.
  2. Basic understanding of network configuration.
  3. Installed Samba package on the Linux server.

Step 1: Install Samba

Update the package index:

sudo apt update # On Debian/Ubuntu

sudo yum update # On CentOS/RHEL

Install Samba:

sudo apt install samba    # On Debian/Ubuntu

sudo yum install samba samba-client  # On CentOS/RHEL

Check the Samba version (optional):

smbstatus --version

Step 2: Configure Samba Share

  1. Create a directory that will be shared over the network. Here, weโ€™ll use /srv/samba/share.
sudo mkdir -p /srv/samba/share

2. Set permissions for the directory to allow Samba access. You can restrict permissions later based on your needs.

sudo chown -R nobody:nogroup /srv/samba/share # On Debian/Ubuntusudo chown -R nobody:nobody /srv/samba/share # On CentOS/RHELsudo chmod -R 0775 /srv/samba/share

3. Open the Samba configuration file to define the share:

sudo vi /etc/samba/smb.conf

4. Add a new share at the end of the file:

[ShareName]
path = /srv/samba/share
browsable = yes
writable = yes
guest ok = yes
read only = no

Explanation of options:

  • [ShareName]: Name of the share that clients will see.
  • path: Path to the shared directory on the server.
  • browsable = yes: Makes the share visible when browsing network shares.
  • writable = yes: Allows write access to the share.
  • guest ok = yes: Allows access without a password (for public shares).
  • read only = no: Enables read and write access.

5. Save and close the file.

Step 3: Set Up Samba User

  1. Add a Samba user (if you want password-protected access):
sudo smbpasswd -a username

2. Set the password for this Samba user when prompted.

  • Note: Samba users must have an account on the Linux server.

3. Restart Samba services to apply the changes:

sudo systemctl restart smbd

sudo systemctl restart nmbd

Step 4: Configure Firewall (if applicable)

If you have a firewall enabled, allow Samba traffic.

  1. Open Samba ports:
sudo ufw allow samba              # On Debian/Ubuntu with UFW
sudo firewall-cmd --permanent --add-service=samba  # On CentOS/RHEL with Firewalld
sudo firewall-cmd --reload

Step 5: Access the Samba Share from Other Computers

1. From a Windows Client

  • Open File Explorer.
  • In the address bar, type \\server_ip_address\ShareName (replace server_ip_address with the IP of your Samba server and ShareName with the name of your Samba share).
  • If prompted, enter the Samba username and password.

2. From a Linux Client

  • Use the following command to mount the share:
sudo mount -t cifs -o username=username,password=password //server_ip_address/ShareName /mnt
  • Replace username, password, server_ip_address, and ShareName with your values.

Step 6: Enable the Samba Share at Boot (Optional)

To automatically mount the Samba share at boot on a Linux client, add it to the /etc/fstab file.

  1. Open the fstab file:
sudo vi /etc/fstab

2. Add the following entry:

//server_ip_address/ShareName /mount/point cifs username=username,password=password 0 0

3. Save and close the file.

4. Test the fstab entry:

sudo mount -a

Step 7: Manage and Troubleshoot Samba

  1. To check the status of the Samba service:
sudo systemctl status smbd

2. To restart Samba if you make configuration changes:

sudo systemctl restart smbdsudo systemctl restart nmbd

3. To view Samba logs for troubleshooting:

sudo tail -f /var/log/samba/log.smbd

Conclusion

Youโ€™ve successfully set up Samba on your Linux server for file sharing across your network. This setup allows Windows and Linux clients to access shared directories on the server. With Samba, you can create a secure a

cloud servers in kenyaservers