Samba4 – Creating users in Samba with shell script

homem segurando tablet

With this script, you’ll be able to create users in Samba4. To execute the steps in this article, you must already have Samba4 configured and functioning as a domain controller. We have created a complete article showing how to install and configure Samba4.

See the article “Configuring Samba as a domain controller“.

With Samba4 prepared, follow the steps below:

Step 1

Create the file

Step 2

Edit the file and add the following content:


list=('user1' 'user2' 'user3' 'user4' 'user5')

for user in ${list[@]}; do
        samba-tool user create $user Pass$123  --home-directory=\\\\ads\\$user

Step 3

Add the users you want to create in place of user1, user2, etc.

Step 4

Personalize o comando de criação dos usuários caso queira adicionar algum parâmetro. Como --script-path para adicionar um script logon para os usuários. Veja informações adicionais sobre parâmetros na documentação do samba4: Adding users with samba tool

Customize the user creation command if you want to add any parameters. Like –script-path to add a login script for users. See additional information about parameters in the Samba4 documentation: Adding users with samba tool

Step 5

Save the file and change the execution permission of the file with the following command:

chmod a+x

Step 6

Execute the script with the command:


Leave a Reply

Your email address will not be published. Required fields are marked *