• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to add or delete a samba user under Linux

by admin

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

Filed Under: CentOS/RHEL 6, CentOS/RHEL 7, Linux, OEL 6, OEL 7

Some more articles you might also be interested in …

  1. httpd Command Examples in Linux
  2. isoinfo: command not found
  3. How to Mirror Swap, Boot and Root Partions in CentOS/RHEL 7 Using mdadm Utility
  4. initctl Command Examples in Linux
  5. man Command Examples in Linux
  6. lvremove Command Fails With Error “LVM – Can’t remove open logical volume”
  7. xargs Command Examples in Linux
  8. kvm-img: command not found
  9. How to transfer files securely using sftp (examples included)
  10. CentOS / RHEL : How to mount filesystems using UUID

You May Also Like

Primary Sidebar

Recent Posts

  • ncat Command Examples in Linux
  • ncat: command not found
  • nautilus Command Examples in Linux
  • namei: command not found

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright