Skip to main content

Creating and Managing Linux Accounts and Groups

Hands-On Lab


Photo of

Training Architect





In this hands-on lab we will be introduced to creating and managing user accounts and groups in a Linux environment.

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.

Creating and Managing Linux Accounts and Groups

Every sysadmin needs to understand how to create and manage user and group accounts in a Linux environment. This lab will let us get our hands dirty with creating our own users and groups.

Become root

All of the commands we'll be running require root privileges, so it will be easier to just become root in the first place:

[cloud_user@host]$ sudo su

Create a New User and Specify Some Attributes

We need to create a user called mphillips and set its full name to Mary Phillips. We want the default shell to be the Bourne Again SHell (Bash), and we want the password set to LinuxPassword. We'll do that with this useradd command:

[root@host]# useradd -c "Mary Phillips" -m  -s "/bin/bash" mphillips

Note that while Ubuntu will create a home directory for the new user, some Linux distros do not. The -m flag will make it happen.

Now, we've got to set Mary's password:

[root@host]# passwd mphillips

We'll be prompted for a new password and prompted to confirm it.

Create a User Account with Default Settings

Now let's create a new user, called richard, using the operating system's default settings:

[root@host]# useradd richard

See the Differences Between the Two Accounts

[root@host]# cat /etc/passwd

There's not much difference between mphillips and richard, but if you'll notice, there isn't a full name for the richard account.

Modify Attributes of the Second User

Let's give Richard a password and a full name:

[root@host]# passwd richard
[root@host]# usermod -c "Richard Layton" richard

Remember, there will be a couple of times we have to enter a password. Once initially, and then once for confirmation.

To verify the changes we made to the account, just cat /etc/passwd again and compare it to the out from the last time we did it.

Create a New Group

Now, let's add a group and call it accounting:

[root@host]# groupadd accounting

Add a User to a Group

We need Richard Layton in the accounting group, so let's add his user account to it now.

[root@host]# usermod -G accounting richard

And check if it worked with this:

[root@host]# groups richard

We'll see this output:

richard : richard accounting

It shows the richard user is part of the richard group (which got created when the user was created), and he's also now part of the accounting group.


You're all set. Congratulations on completing this lab!