The user and group Modules

Length: 00:07:41

Lesson Summary:

It is beneficial to have a grasp of user and group management through the use of execution modules. This lets us quickly add and remove users, as well as add and remove groups, and add and remove users to groups. We can also manage things like a user's home directory, default shell -- anything that you would normally think to manage regarding a user.

Like our pkg module, these are virtual modules. user combines the nix useradd, userdel, and usermod features, with BSD's pw, and Mac and Windows' user management functionalities (which are traditionally done in a GUI). The group module also combines nix, BDS, MacOS, and Windows group functionalities.

Add salt Group

This is as easy as running a single command:

$ sudo salt 'salt' group.add salt

This might be a little hard, given all the instances of the word salt, so let's take a moment to remember how we break down commands:

sudo salt '' group.add 

Note there are additional arguments we could use -- gid, system, and root -- but none we need to use in this instance. We're also only running this on our salt Master server because we won't be working directly with Salt on our minions.

Now, let's go ahead and add our user user:

$ sudo salt 'salt' group.adduser salt user

Notice that the name of the group we're adding the user to comes before the username.

Add New User

We also want to go ahead and add a user for ourselves -- after all, we are an employee at IdunnaSoft in this course. Unlike most of the commands we've used thus far, however, the user command has a number of arguments we generally want to include. Let's take a look:

$ salt 'salt' sys.argspec user.add

salt:
    ----------
    user.add:
        ----------
        args:
            - name
            - uid
            - gid
            - groups
            - home
            - shell
            - unique
            - system
            - fullname
            - roomnumber
            - workphone
            - homephone
            - createhome
            - loginclass
            - root
            - nologinit

Let's add a user with our information. Here's mine:

$ sudo salt 'salt' user.add elle groups=salt,sudo home=/home/elle shell=/bin/bash fullname="Elle K"

I included arguments for our user's home directory, the default shell, full name, and also included our new user in our newly-created salt group, not to mention granted them superuser privileges.

Whether you use your new user to continue within this course, or continue using the user user, is up to you! If you want to use your own user, you'll have to set a password.

Set Password

  1. Hash the password you wish to use:

     $ sudo salt 'salt' shadow.gen_password 'mypassword'
    
  2. Use the hash to set a password for your new user:

     $ sudo salt 'salt' shadow.set_password elle '$6$8stAtY6O$9o8prUuAeg94heacqhN2SsOTWQ/Kz7YzZOuByAKSQ9yREYn35Xax1xSXs0iBWFKZSRt3tO6o.bZSWkIun65Qe0'
    


This lesson is only available to Linux Academy members.

Sign Up To View This Lesson
Or Log In

Looking For Team Training?

Learn More