How to add a Samba User on Linux

Samba is a file-sharing service that can connect two or more computers on a network- you can even share files between Linux and Windows machines. But what happens when you get a new coworker who needs to be added to the share?


This article assumes that you already have a Samba server set up and running.


Here is the process for adding a Samba user on Linux.

Make a System User for Samba on Linux

If the new user does not exist on the server already, you’ll need to add a new user account. Say our new coworker’s name is Sam.


# sudo useradd sam


Of course, there are many options you can pass to useradd to give this user more or less permissions and abilities within the system. For now, we’re just setting him up as a default user.


Note: This username must be the same as the user on the other connecting systems. Otherwise, you can map the usernames using a configuration option in smb.conf. For example if Sam’s Windows username is SamB, you can use what’s called “user mapping” to connect them.

User Mapping on Samba

In /etc/samba/smb.conf is a configuration option that allows you to provide a mapping of usernames for Linux to Windows. So if Sam is “sam” on Linux and “SamB” on Windows, this is how you’d set it up.


First, in /etc/samba/smb.conf, specify where the file that has the mapping lives:


username map = /path/to/mapping.txt


Now we need to create the mapping file itself. Be sure you create the file in the same location specified in smb.conf. Using one line per user, the mappings follow this format:


![server_user] = [client_user]

Define Samba Password

Now that the user account is on the server, we need to tell Samba about it.


# smbpasswd -a sam

New SMB password: ********

Retype new SMB password: ********


This password can be different from the password that Sam uses to log in. The Samba password file and the Linux password file are separate, so Samba only knows about passwords in smbpasswd.

Add to smb.conf in Samba

Finally, we need to add our new user to the list of allowed users on Samba. You can find this list in the /etc/samba/smb.conf file.


If you already have a share set up, you’ll see a section that looks something like this:



comment = Shared data directory

path = /data/shared

valid users = al kevin

public = no

writable = yes


If you want to add Sam to sharedir, then you need to put his Samba name on the line that says “valid users.”



comment = Shared data directory

path = /data/shared

valid users = al kevin sam

public = no

writable = yes


There, we’ve added Sam. Save and close the file. There’s one more step to do before Sam can access the share, though.

Restart Samba

Once you’ve saved your changes, you’ll need to restart Samba to see the new permissions take effect.


$ sudo service smbd start


At this point, the new user should have access to the Samba network share.