How to Add a Samba User in Linux

Last updated: August 7, 2022

Samba is a free and open-source networking service that functions in a client/server networking model. It allows for file sharing across both Windows and Linux/Unix operating systems and leverages the SMB (Server Messaging Block) and the CIFS (Common Internet File system) protocols to seamlessly share resources in a network. Samba sharing is considered one of the most efficient and cost-effective way of sharing resources in a local area network - LAN.

A file share in Samba in referred to as a samba share. A samba share could be anything from a file, a directory, or even a printer. In a network setup, the client sends a request to the Samba server for a file, directory, or a shared printer. In turn, the Samba server responds to these requests by denying or granting the client access to the shared resources requested.

A new user needs to be added as a samba user in Linux to be able to access the samba share. The samba user can then connect to the Samba server using a samba password and access the shared resources. In this tutorial, we will walk you the procedure of adding a samba user

Add a user

Now let's focus on how to add a new user to Samba. First, create a new user account just as you would in any Linux system. In this example, we will create a new user account for a user called 'joe'.

adduser joe

Next, add samba user by assigning a samba password to the new user using the 'smbpasswd' command as shown:

sudo smbpasswd -a joe

You will be prompted to provide a new samba password and later confirm it as shown in the output below

New SMB password:
Retype new SMB password:
added user joe.

The samba users passwords are stored in a binary file located in /var/lib/samba/private directory. The file is named as passdb.tdb. You won't be able to view the password - it's hashed. To manage TDB databases in Linux systems you can use Tdbtool - is a command-line utility.

Once you have created the samba user, you need to add them to the samba share by editing the samba smb.conf file which is Samba's configuration file. Scroll and locate the samba share, in this case, 'documents', and append the user to the list of valid users as shown in the 4th line in the configuration block below.

comment = Departmental documents share
path = /srv/documents
valid users = joe
public = no
writable = yes
browsable = yes

Now save the changes and exit the configuration file. For the changes to persist, restart Samba daemon as shown.

sudo systemctl restart smb

Add existing local user to samba

If you already have an existing user on your system, then adding the user to samba is quite straightforward. Simply use the 'smbpasswd' command as shown:

sudo smbpasswd -a existing_user

Then modify the configuration file and add the existing user to the list of valid samba users as shown earlier.

valid users = existing_user

A point on Adding users to Samba version 4.x

From Samba version 4.x and later, Samba has the ability to run as an AD Domain Controller. You don't need to have a standard Linux or Unix user in Linux for every Samba user that is created. To add users into Samba Active directory, use the command shown:

samba-tool user add username

Delete samba user

If you want to delete or remove a Samba user from your system, use the 'smbpasswd' command with -x option followed by the username.

sudo smbpasswd -x joe

If you so desire, you can remove the user completely along with the home directory using the userdel command as shown:

sudo userdel -r joe


We have covered how you can add and delete a Samba user on a Linux system. As stated earlier, the Samba version 4.x now supports authentication via the Active directory unlike the earlier versions of Samba.

About The Author

James Kiarie

James Kiarie

James is a certified LPIC Linux administrator and passionate Linux technical writer. He has over 4 years of penning down technical guides in Linux administration with ample experience in a range of distributions such as Ubuntu, CentOS, RHEL, Fedora, Rocky, and AlmaLinux to mention a few. In addition, he has also spread his wings wider to cloud computing and DevOps tools such as Terraform, Docker, and Kubernetes. During his free time, I love swimming, listening to music, reading books, and taking evening runs after a busy day.



Please add comments below to provide the author your ideas, appreciation and feedback.

Comments Off on How to Articles