Samba Add a User

I am using Fedora Linux and I would like to add a user called joe to Samba. How do I add a user SMB share? How can I add a users to Samba?

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Samba
Est. reading time 5m
[/donotprint]The procedure is as follows to add a user to samba server: [a] First add Linux/UNIX user using useradd/adduser command. [b] Then use same user name to add to Samba share using smbpasswd command.

NOTE: Unlike Samba 3, Samba 4 does not require a local Unix user for each Samba user that is created. Please see this note for more info.

Step # 1: Add a user joe to UNIX/Linux system

adduser command adds user to the system according to command line options and configuration information in /etc/adduser.conf. They are friendlier front ends to the low level tools like useradd.

Type any one of the following command:
# useradd joe
# passwd joe

adduser joe

Step # 2: Add a user to samba

Now user joe has account on Linux/UNIX box. Use smbpasswd command to specifies that the username following should be added to the local smbpasswd file:
# smbpasswd -a joe

Step # 3: Add a user to a Samba share

By default user gets access to /home/joe from windows system. Let us say you want to give joe access to /data/accounts (make sure directory /data/accounts exists) directory. Open /etc/samba/smb.conf file and add/modify share called [accounts]:

comment = Accounts data directory
path = /data/accounts
valid users = vivek raj joe
public = no
writable = yes

Save the file.

Step #4: Restart the samba

# service smb restart
# /etc/init.d/smb reload

A note about adding users on Samba version 4.x

Unlike Samba version 3.x and earlier, Samba version 4.x does not require a local Unix/Linux user for each Samba user that is created. The command is as follows for adding users into Samba Active Directory:
# /usr/local/samba/bin/samba-tool user add USERNAME-HERE
# samba-tool user add USERNAME-HERE
Please see Samba AD DC howto for more info.

See also:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 19 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf duf ncdu pydf
File Managementcat cp mkdir tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Modern utilitiesbat exa
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg glances gtop jobs killall kill pidof pstree pwdx time vtop
Searchingag grep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
19 comments… add one
  • Juan Jun 10, 2010 @ 1:08

    Good info; worked as expected under CentOS 5.5

  • Vimo Feb 3, 2011 @ 11:49

    Dear Nixcraft,
    Would you pls tell me how to do this without prompting win users for a password? I have been banging my head on wall over this Gentleman. Following is my smb.conf.
    workgroup = MYGROUP
    server string = Samba Server Version %v
    security = share
    passdb backend = tdbsam
    load printers = yes
    cups options = raw
    comment = Home Directories
    browseable = no
    writable = yes
    ; valid users = %S
    ; valid users = MYDOMAIN\%S
    comment = All Printers
    path = /var/spool/samba
    browseable = no
    guest ok = no
    writable = no
    printable = yes

    comment = ux_share
    writable = yes
    path = /home/ux_share/share
    guest ok = yes
    browseable = yes

    I have added a user called ux_share in the system and created the /home/ux_share/share with the right permission. And created the smbuser ux_share too. Now when I try to access the share from a winbox it prompts for the passw. Please help out Nixcraft. This share is likely to access by several winusers and i have no idea about thier workgroup names whatsoever. This is just a simple share im trying to publish just like an annonymous vsftpd account.


  • Karthigayan Mar 31, 2011 @ 8:49

    Good work

  • manoj Oct 27, 2011 @ 10:24

    please reply ,

    q) what are the steps to be followed to share a folder in Ubuntu and access it from different machine in the network for different clients (eg ,root ,admin ,student..)

    thanking u …

  • yubaraj Jan 19, 2012 @ 11:12

    Samba permission problem

    /home can’t be accessed from windows client for samba.
    /tmp can be accessed but /home can’t be accessed.

    Any solution

  • Reza Safe Sep 15, 2012 @ 5:26

    @yubaraj :
    1) restart winbind
    2) chmod 777 -R /home

  • firion Dec 8, 2012 @ 12:34

    hello, i have a question here..
    what a use of 2 user samba in same time…???
    example i have 2 user samba, John and Billy..
    and i created a folder name is ” Work “..
    and then, how John and Billy user can access that folder ” Work ” at the same time…

    pls reply this..
    thank’s a lot…

    • sheba Jan 10, 2013 @ 8:45

      valid users=John, Billy

  • harsh Jan 15, 2013 @ 12:16

    i have made two samba users…
    harsh & gaurav

    and made an entry for “valid user ” under [ IT ]




  • Sharmazan Feb 16, 2013 @ 17:12

    Thanks a lot!

    Your site make it easy! )

  • suresh Oct 28, 2013 @ 15:36

    run this in command prompt
    net use * /delete

    This will clear all existing password cache and will prompt for password

  • Chathuranga Apr 20, 2014 @ 10:43

    thanks for your support this is very helpfull for my exam thanks

  • dietrich Jan 15, 2015 @ 21:14

    Perfect! Worked on Ubuntu 14.04 with latest SMB. Thank You Very Much!

  • Bob Feb 15, 2015 @ 20:39

    Getting an error when trying to add a samba user:

    bob@bob-K55A:~$ sudo samba-tool user add timebandit
    New Password:
    Retype Password:
    ERROR(): Failed to add user ‘timebandit’: – unable to parse dn string
    File “/usr/lib/python2.7/dist-packages/samba/netcmd/”, line 176, in run
    uid=uid, uidnumber=uid_number, gidnumber=gid_number, gecos=gecos, loginshell=login_shell)
    File “/usr/lib/python2.7/dist-packages/samba/”, line 343, in newuser
    dnsdomain = ldb.Dn(self, self.domain_dn()).canonical_str().replace(“/”, “”)

    Any idea what to do?

    • Dowlers May 23, 2015 @ 20:22

      I am also getting this error, did you ever find a solutions?

  • Steve H May 21, 2015 @ 20:22

    Worked on Ubuntu version 14.04.. thanks dude!

  • Vladyck Dec 4, 2015 @ 14:47

    Hallo. what is wrong with me? samba-tool user add temp2 –home-directory=’\\ubuntu\home\temp2 is not creating home directory!
    directory_mode: parameter = 0700
    read only = no
    path = /Users
    csc policy = documents
    comment = Home Directories
    browseable = no
    read only = no
    create mask = 0700
    directory mask = 0700
    valid users = %S
    path = /Users/home/
    read only = no

  • Mike Jo Jan 22, 2016 @ 17:32

    That last command to restart Samba, for me on Debian Jessie, was:
    /etc/init.d/smbd reload
    sudo /etc/init.d/smbd reload

  • Manaswini Maharana Oct 6, 2017 @ 19:46

    m doing file sharing using SMB protocol on centos linux and when m trying to map the network drive it is asking for username and password…but the problem is that after creating different user and password it never accepts any of those….it only accepts the root username and root as the password…why only root..pls tell me how to solve this problem.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum