How to Add and Delete a User in Samba on Linux
Step-by-step guide to managing Samba users on Linux for secure file sharing across Windows and Linux networks. Perfect for VPS and dedicated server users.
What is Samba?
Samba is a powerful tool that bridges Linux and Windows systems for seamless file sharing. Whether you are managing a secure server or building a collaborative network, adding users correctly is key to maintaining control and trust.
Prerequisites
- Samba is installed (
sudo apt install samba) - You have root or sudo privileges
- The Linux user already exists or will be created
- Your system is connected to the network
Step 1: Create or Verify the Linux User
Before adding a Samba user, the corresponding Linux user must exist:
sudo adduser username
If the user already exists, skip this step.
Step 2: Add the User to Samba
sudo smbpasswd -a username
You will be prompted to set a Samba-specific password. This password is stored securely in Samba's passwd database and can differ from the Linux login password.
Step 3: Configure Samba Share Access
Edit the Samba configuration file:
sudo nano /etc/samba/smb.conf
Add a share block like this:
[shared]
path = /srv/samba/shared
valid users = username
read only = no
browsable = yes
valid users restricts access to specific Samba users. read only = no allows write access.
Step 4: Restart Samba Services
sudo systemctl restart smbd
sudo systemctl restart nmbd
How to Delete a Samba User
sudo smbpasswd -x username
To also remove the Linux user entirely:
sudo userdel -r username
Pro Tips for Secure File Sharing
- Use strong, unique passwords for each Samba user
- Limit access with valid users and Unix permissions
- Monitor
/var/log/sambafor suspicious activity - Consider Samba 4.x with Active Directory integration for enterprise setups
Running a Linux VPS or dedicated server and need reliable hosting? KMWEBSOFT provides affordable Linux VPS with full root access from $30/month — perfect for Samba file servers and other Linux workloads.
Written by KM Joshi
Senior Linux Administrator | Connect on LinkedIn
Ready to Get Started? 🚀
Professional hosting from $5/month. Done-for-you setup. Human support always.