Twitter icon LinkedIn Icon Github Icon Stackoverflow Icon

How to Add a Samba User From the Command Line

By: Roger Creasy

Adding Samba users is likely a task that you have to do irregularly. Here is a simple set of instructions that I hope can be a resource. Entries inside <> should be replaced, without the <>, with your entries. Entries inside [] are optional.  One exception is that the Samba share name is inside [].

  1. If the user does not have an account on the server, create a user account for them on the server:

    sudo adduser --no-create-home [--disabled-password --disabled-login] <username>

  2. Add that user to samba (you'll be asked to type a password):

    sudo smbpasswd -a <username>

    (to change an existing user's password)
    sudo smbpasswd -u <username>

  3. Optional -- Create a share by editing /etc/samba/smb.conf. For example, you can add something like this to the bottom:

    [share name]
    comment = <whatever you want to explain what the share is for>
    path = </path/to/share>
    valid_users = <username, username, uesrename ...>

  4. browsable = <yes/no>
    read only = <yes/no>
    guest ok = <yes/no>

  5. Add the user to the 'Valid Users' and, optionally  'Write list' 
  6. Add the user to the "sambausers" group
    usermod -aG sambausers <username>
  7. Restart samba:

    sudo service smb force-reload
    sudo service nmb force-reload

  8. Go to the client machine and try to access the share with the username and password you've just set up.

Publication Date: 2018-07-25 09:32:45