To add a new user to access a samba share you need to first create a server user account using “useradd” command and then use the same account to add the samba user. Follow the steps givenbelow to add user zach and give him the access to a samba share.


Adding a Linux user account


One way for a user to browse a Samba share is have a UNIX account on the Samba server. This is done via the commands ‘useradd [username]‘ and ‘passwd [username]‘. If you already have the user account created on the system, skip the part below and proceed to add samba user directly.

# useradd zach


Set the password for the new user created.

# passwd zach


Adding Samba user


Once the user has a local account their corresponding Samba samba user can be added using smbpasswd -a command. The smbpasswd command when used with -a option adds the new samba user and also allows you to set the password for the new samba user. For example for the user zach, use the command below:

# smbpasswd -a zach
New SMB password:
Retype new SMB password:


The -a switch adds zach to the Samba password list.


To modify an existing Samba user’s Samba password (using the example zach user again):

# smbpasswd zach
New SMB password:
Retype new SMB password:


Allowing user to access samba share


Configure the Samba share in the /etc/samba/smb.conf configuration file to allow the new user to browse the share:

# vi /etc/samba/smb.conf
   comment = A Shared Directory
   path = /var/tmp/sharedir
   valid users = anthony zach
   public = no
   writable = yes


Use testparm to show your updated share. Reload the smb.conf configuration file with below command.

# passwd zach


For RHEL/CentOS 6

# service smb reload


For RHEL/CentOS 7

# systemctl reload smb


Deleting the Samba user


In order to delete the samba user, use the steps below. make sure you delete the corresponding UNIX user from the server as well if required.


1. delete samba user(zach) using smbpasswd command with -x option.

# smbpasswd -x zach
delete unix user(zach) by userdel


2. You can now delete the UNIX OS user zach along with all the files associated with the user like home directory, using the ‘userdel -r’ command.

# userdel -r zach


Was this answer helpful? 3 Users Found This Useful (6 Votes)