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 [].
-
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>
-
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> -
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 ...> -
browsable = <yes/no>
read only = <yes/no>
guest ok = <yes/no> - Add the user to the 'Valid Users' and, optionally 'Write list'
- Add the user to the "sambausers" group
usermod -aG sambausers <username> -
Restart samba:
sudo service smb force-reload
sudo service nmb force-reload -
Go to the client machine and try to access the share with the username and password you've just set up.