How to Add or Delete a Samba User Under Linux?

Samba is a free and open-source software suite that allows their users to share files and printers with Windows, Linux and Unix systems over a network. Adding or removing a samba user in Linux is to control access to shared resources on a network that uses the SMB/CIFS protocol.

This article will provide methods to add and delete samba users in Linux. The content of this article is given below:

Prerequisite: Install Samba in Linux

It is necessary to install samba before adding or removing the samba user in linux. For this, follow the below commands to install the samba in linux distributions:

$ sudo apt install samba              # Ubuntu Debian LinuxMint
$ sudo yum install samba samba-client # CentOS
$ sudo dnf install samba              # Fedora

After successfully installing the samba installation, let’s add the new samba user.

Add a Samba User in Linux

To add a new Samba user under Linux, utilize the “smbpasswd” command with the “a” option. This command is utilized to set and change passwords for Samba users to access the shared resources. For instance, we specified the username “johnson” to add a samba user:

$ sudo smbpasswd -a johnson

The output shows that a new samba user, “johnson”, has been added after entering and confirming a password.

Access the Samba Server (To Verify the User)

You can edit the file “/etc/samba/smb.conf” to add or remove the user from the valid user list. It allows access to or restricts the samba server, according to requirement. Add the samba user “Roger” after accessing the particular file:

$ sudo nano /etc/samba/smb.conf

The output shows that a new user, “Roger”, has been added as a samba user to access the shared resources.

Restart the Samba Service

It is necessary to restart the samba service after adding or deleting a user. It is possible by executing the below command:

$ sudo service smbd restart

The output shows that “samba” services have been restarted in the terminal.

Delete a Samba User in Linux

To delete a Samba user, utilize the “smbpasswd” command with the “x” option by specifying the user’s name. In our case, existing samba user “johnson” is utilized to delete from the system:

$ sudo smbpasswd -x johnson

The above command deletes the specified user from the samba user database. When a user is removed, they are no longer able to access the shared resources.


Linux offers the “smbpasswd -a” and “smbpasswd -x” commands to add and delete samba users in Linux. Before adding or removing samba users, installing the “samba” package in the system is necessary. This can restrict access to certain files or folders on the network or revoke user access. This article has explained methods to add or delete samba users in Linux.