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 john 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 john
Set the password for the new user created.
# passwd john
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 john, use the command below:
# smbpasswd -a john New SMB password: Retype new SMB password:
The -a switch adds john to the Samba password list.
To modify an existing Samba user’s Samba password (using the example john user again):
# smbpasswd john 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 [share1] comment = A Shared Directory path = /var/tmp/sharedir valid users = anthony john public = no writable = yes
Use testparm to show your updated share. Reload the smb.conf configuration file with below command.
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(john) using smbpasswd command with -x option.
# smbpasswd -x john delete unix user(john) by userdel
2. You can now delete the UNIX OS user john along with all the files associated with the user like home directory, using the ‘userdel -r’ command.
# userdel -r john