Samba4 – Creating Groups and Adding Users

rede de grupos e usuarios
Share

With this script, you will be able to create groups and assign users in Samba4. To execute the steps in this article, you must already have Samba4 installed and functioning as a domain controller. We have created a comprehensive 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 add_groups.sh.

Step 2

Edit the file and add the following content:

#!/bin/bash

# Array with system groups
all_groups=('group_a' 'group_b' 'group_c')

for group in ${all_groups[@]}
    do
        samba-tool group add $group
        case $group in
            group_a)
                samba-tool group addmembers $group user1
                samba-tool group addmembers $group user2
            ;;
            group_b)
                samba-tool group addmembers $group user1
                samba-tool group addmembers $group user2
                samba-tool group addmembers $group user3
            ;;
            group_c)
                samba-tool group addmembers $group user2
                samba-tool group addmembers $group user3

            ;;

    esac
done

Step 3

Add the groups you want to create in place of group_a, group_b, etc.

Step 4

Add the users you want to assign to each group in place of user1, user2, etc.

Step 5

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

chmod a+x add_groups.sh

Step 6

Execute the script with the command:

./add_groups.sh

Leave a Reply

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