Samba Add a User

See all Fedora Linux related FAQ
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 2 minutes
[/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:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

19 comments… add one
  • 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. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.