CloudsArk
RHCSA Linux

Create Users and Groups in Linux

Learn how to create and manage Linux users and groups using useradd, groupadd, passwd, usermod, and related commands.

Create Users and Groups in Linux

Managing users and groups is one of the most important Linux administration tasks. Every Linux system depends on users, groups, permissions, and ownership to control access to files, directories, commands, and services.

In this guide, you will learn how to create users and groups in Linux using practical commands that are useful for system administration and RHCSA preparation.


What You Will Learn

By the end of this guide, you should be able to:

  • Create a new Linux user
  • Set a password for a user
  • Create a new Linux group
  • Add a user to a group
  • Create a user with a specific home directory
  • Create a user with a specific shell
  • Lock and unlock user accounts
  • Verify user and group information

Understanding Linux Users

A Linux user account represents a person, service, or process that can access the system.

Each user has:

  • Username
  • User ID, also called UID
  • Primary group
  • Home directory
  • Login shell

User account information is stored in:

/etc/passwd

You can view user account entries using:

cat /etc/passwd

Example entry:

student:x:1001:1001:Student User:/home/student:/bin/bash

This means:

Field Meaning
student Username
x Password is stored in /etc/shadow
1001 User ID
1001 Primary group ID
Student User Comment field
/home/student Home directory
/bin/bash Login shell

Create a New User

To create a new user, use the useradd command.

sudo useradd student

This creates a user called student.

To confirm the user was created:

id student

Example output:

uid=1001(student) gid=1001(student) groups=1001(student)

You can also check the /etc/passwd file:

grep student /etc/passwd

Set a Password for a User

After creating a user, set a password using the passwd command.

sudo passwd student

You will be asked to enter and confirm the password.

Example output:

New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Without a valid password, the user may not be able to log in using normal password authentication.


Create a User with a Home Directory

On many Linux distributions, useradd may not always create a home directory unless you use the -m option or the system defaults are configured to do so.

To create a user with a home directory:

sudo useradd -m devuser

This creates a home directory for the user:

/home/devuser

Verify it:

ls -ld /home/devuser

Create a User with a Specific Shell

You can specify the login shell using the -s option.

sudo useradd -m -s /bin/bash devuser

This creates the user devuser with /bin/bash as the login shell.

To verify:

grep devuser /etc/passwd

Example output:

devuser:x:1002:1002::/home/devuser:/bin/bash

Create a User with a Comment

The comment field is often used to store the full name or description of a user.

Use the -c option:

sudo useradd -m -c "DevOps User" devops

Verify:

grep devops /etc/passwd

Example output:

devops:x:1003:1003:DevOps User:/home/devops:/bin/bash

Create a New Group

Groups are used to manage permissions for multiple users.

To create a new group:

sudo groupadd developers

Verify the group:

getent group developers

Example output:

developers:x:1004:

Group information is stored in:

/etc/group

You can also check it using:

grep developers /etc/group

Add a User to a Group

To add an existing user to an additional group, use usermod -aG.

sudo usermod -aG developers student

Important: use -aG, not just -G.

The -a option means append. Without it, you may replace the user's existing supplementary groups.

Verify the user groups:

id student

Example output:

uid=1001(student) gid=1001(student) groups=1001(student),1004(developers)

Create a User and Add Them to a Group

You can create a user and assign them to a supplementary group at the same time.

sudo useradd -m -G developers appuser

Then set the password:

sudo passwd appuser

Verify:

id appuser

Create a User with a Specific Primary Group

Every Linux user has one primary group.

First, create the group:

sudo groupadd appteam

Then create the user with that group as the primary group:

sudo useradd -m -g appteam appadmin

Verify:

id appadmin

Example output:

uid=1005(appadmin) gid=1005(appteam) groups=1005(appteam)

Change a User's Primary Group

To change the primary group of an existing user:

sudo usermod -g appteam student

Verify:

id student

Be careful when changing a primary group because it can affect file ownership and access behavior.


Add a User to Multiple Groups

You can add a user to multiple supplementary groups.

sudo usermod -aG developers,admins,webteam student

Verify:

id student

Create a User with an Expiry Date

You can create a temporary user account with an expiry date.

sudo useradd -m -e 2026-12-31 contractor

Set a password:

sudo passwd contractor

Verify account expiry information:

sudo chage -l contractor

Lock a User Account

To lock a user account:

sudo usermod -L student

Or:

sudo passwd -l student

This prevents password-based login for the account.

Verify the account status:

sudo passwd -S student

Unlock a User Account

To unlock a user account:

sudo usermod -U student

Or:

sudo passwd -u student

Verify:

sudo passwd -S student

Delete a User

To delete a user but keep their home directory:

sudo userdel student

To delete a user and remove their home directory:

sudo userdel -r student

Be careful with -r because it removes the user's home directory and mail spool.


Delete a Group

To delete a group:

sudo groupdel developers

Verify:

getent group developers

If the command returns no output, the group no longer exists.


Useful User Management Commands

Command Purpose
useradd Create a user
passwd Set or change a user password
usermod Modify an existing user
userdel Delete a user
groupadd Create a group
groupdel Delete a group
id Show user and group IDs
groups Show groups for a user
getent passwd Query user database
getent group Query group database
chage Manage password ageing

Practical RHCSA-Style Example

Create a group called sysadmins.

sudo groupadd sysadmins

Create a user called john with a home directory and Bash shell.

sudo useradd -m -s /bin/bash john

Set a password for john.

sudo passwd john

Add john to the sysadmins group.

sudo usermod -aG sysadmins john

Verify the result.

id john

Expected output should show that john belongs to the sysadmins group.


Common Mistakes

Forgetting -a with usermod -G

Wrong:

sudo usermod -G developers student

This can replace the user's existing supplementary groups.

Better:

sudo usermod -aG developers student

Creating a User Without a Home Directory

If the user needs to log in normally, create a home directory:

sudo useradd -m username

Not Setting a Password

After creating a user, remember to set a password if password login is required:

sudo passwd username

Quick Checklist

When creating a normal Linux user, check the following:

  • Was the user created?
  • Does the user have a home directory?
  • Does the user have the correct shell?
  • Is the password set?
  • Is the user in the correct groups?
  • Can you verify the account using id and getent?

Summary

Creating users and groups is a core Linux administration skill. The most important commands are useradd, passwd, groupadd, usermod, id, and getent.

For RHCSA preparation, you should be comfortable creating users, assigning groups, setting passwords, modifying account properties, and verifying the final configuration from the command line.