Skip to main content

Managing Users in Linux

Hands-On Lab

 

Photo of Rob Marti

Rob Marti

Linux Training Architect I in Content

Length

00:30:00

Difficulty

Beginner

In this lab we are going to manage users and groups to get some practice using these utilities. Knowing how to manage users and permissions means our servers will be more secure.

What are Hands-On Labs?

Hands-On Labs are scenario-based learning environments where learners can practice without consequences. Don't compromise a system or waste money on expensive downloads. Practice real-world skills without the real-world risk, no assembly required.

Managing Users in Linux

Introduction

In this lab we are going to manage users and groups to get some practice using these utilities. Knowing how to manage users and permissions means our servers will be more secure.

The Scenario

We have some users that need to be set up on a new machine.

Tony Stark, Diana Prince, and Carol Danvers are developers for a project we're involved with. We need to add user accounts for them to the server, then create the superhero group for all of them to be members of.

Tony Stark is a superuser, so we'll replace his primary group with the wheel group.

But wait! We realize a couple weeks in that Diana Prince has been forced to take leave, in order to fight evil. We'll have to lock her account until she can return.

Get Logged In

Use the credentials and server IP in the hands-on lab overview page to log into our lab server. Since we'll need to be root for the all of the commands, we'll run a quick sudo -i as soon as we're in. Once that's done, we can get moving.

Add the Users to the Server

To add users to the system we can run the useradd command. To add our users, we're going to run:

[root@host]# useradd tstark
[root@host]# useradd cdanvers
[root@host]# useradd dprince

Create the superhero Group

We create new groups with the groupadd command. To make this one, we'll run this:

[root@host]# groupadd superhero

Set wheel Group as the the tstark Account's Primary Group

The usermod command will change which group a user is in. We'll change the tstark one like this:

[root@host]# usermod -g wheel tstark

Check this afterward with a quick id tsark. That command's output should show his primary group now being wheel.

Add superhero as a Supplementary Group on All Three Users

There isn't an easy way to do this all at once, so we need to run the usermod command for each user, like this:

[root@host]# usermod -aG superhero tstark
[root@host]# usermod -aG superhero dprince
[root@host]# usermod -aG superhero cdanvers

We can check any of these like with did with the tstark group change. Just run id &ltUSERNAME> and we'll see that they're now in the superhero, as well as their own groups.

Lock the dprince Account

To lock an account all we have to do is run:

[root@host]# usermod -L dprince

Conclusion

Well, we did it. We got all of the required users set up and in the groups they needed to be in. And in the end, we were able to lock Diana's account down while she flies her invisible jet around chasing criminals. Congratulations!