Saturday, September 5, 2026

Linux User Management — Practical Lab

1. Check your current user

Run:

whoami

id

 

You should see information such as your UID, GID, and groups.

Also try:

who

w


List All Registered Users (Local + Network)

Try:

getent passwd


List Only Local Users

Try:

cat /etc/passwd


List Human/Regular Users Only (Cleanest Table)

lslogins -u


Practice task:-

Find:

  • Your username
  • Your UID
  • Your primary group
  • All groups you belong to

2. Create a New User

Create a test user:

sudo adduser devuser1

Ubuntu will ask:

New password:
Retype new password:
Full Name:
Room Number:
Work Phone:
Home Phone:
Other:

You can press Enter for the optional information.

Check the user:

id devuser1

And:

getent passwd devuser1

Practice

Create two users:

sudo adduser devuser1

sudo adduser devuser2

Then verify:

id devuser1

id devuser2

 

3. Switch to Another User

Try:

su - devuser1

Check:

whoami

It should show:

devuser1

Then:

pwd

You should be in:

/home/devuser1

Return to your original user:

exit

 

4. Create a User Without Interactive Questions

You can also use:

sudo useradd -m devuser3

The -m option creates the user's home directory.

Check:

ls /home

You should see:

devuser1
devuser2
devuser3

Set a password:

sudo passwd devuser3

 

5. Understand /etc/passwd

Run:

cat /etc/passwd

You'll see entries similar to:

devuser1:x:1001:1001:,,,:/home/devuser1:/bin/bash

The important fields are:

username : password : UID : GID : comment : home : shell

For a specific user:

getent passwd devuser1

 

6. Understand /etc/shadow

Run:

sudo cat /etc/shadow

This file contains password hashes and password-aging information.

Do not modify this file manually.

Instead, use:

passwd

or:

sudo passwd username

 

7. Change a User's Password

Change devuser1 password:

sudo passwd devuser1

Test it:

su - devuser1

Enter the new password.

 

8. Lock a User Account

Lock the account:

sudo passwd -l devuser1

Check its status:

sudo passwd -S devuser1

You can also use:

sudo usermod -L devuser1

Try logging in:

su - devuser1

Depending on the configuration, authentication should fail because the account is locked.

 

9. Unlock a User

Unlock it:

sudo passwd -u devuser1

or:

sudo usermod -U devuser1

Check:

sudo passwd -S devuser1

 

10. Create Linux Groups

Create a group:

sudo groupadd developers

Check:

getent group developers

Create another:

sudo groupadd testers

 

11. Add User to a Group

Add devuser1 to developers:

sudo usermod -aG developers devuser1

Check:

groups devuser1

Or:

id devuser1

You should see developers.

⚠️ Important

Always use:

usermod -aG

The -a means append.

Without -a, you can accidentally replace the user's supplementary groups.

 

12. Add User to Multiple Groups

For example:

sudo usermod -aG developers,testers devuser1

Check:

id devuser1

 

13. Remove a User from a Group

For example:

sudo gpasswd -d devuser1 testers

Verify:

groups devuser1

 

14. Make User a Sudo User

This is an important Linux administrator task.

Add devuser1 to the sudo group:

sudo usermod -aG sudo devuser1

Check:

groups devuser1

Then switch:

su - devuser1

Run:

sudo whoami

It should return:

root

What happened?

You gave devuser1 permission to execute authorized commands with elevated privileges.

 

15. Remove Sudo Permission

Return to your original user:

exit

Then:

sudo gpasswd -d devuser1 sudo

Verify:

groups devuser1

 

16. Change a Username

Suppose you want to rename:

devuser2

to:

developer

Run:

sudo usermod -l developer devuser2

But the home directory will still need attention.

You can rename the home directory:

sudo usermod -d /home/developer -m developer

Verify:

getent passwd developer

 

17. Delete a User

Delete the user:

sudo userdel devuser3

This normally removes the account but may leave the home directory.

To delete the account and its home directory:

sudo userdel -r devuser3

Verify:

id devuser3

You should get something like:

id: ‘devuser3’: no such user

 

18. Check User Login Shell

Run:

getent passwd devuser1

At the end you may see:

/bin/bash

This is the user's login shell.

You can also use:

echo $SHELL

 

19. Change User's Shell

For example, change devuser1 to Bash:

sudo usermod -s /bin/bash devuser1

Check:

getent passwd devuser1

You can see available shells with:

cat /etc/shells

 

20. Set Account Expiration

You can set an expiration date:

sudo usermod -e 2026-12-31 devuser1

Check:

sudo chage -l devuser1

This is useful for temporary employees, contractors, and test accounts.

 

21. Password Expiration

Check password aging:

sudo chage -l devuser1

You can require a user to change their password on the next login:

sudo chage -d 0 devuser1

 

22. Force Password Expiration

For example:

sudo chage -M 90 devuser1

This means the password expires after 90 days.

Check:

sudo chage -l devuser1

 

23. Find All Users

Use:

cat /etc/passwd

 

Only username:

cut -d: -f1 /etc/passwd

 

Show normal human users:

awk -F: '$3 >= 1000 {print $1}' /etc/passwd

 

This can show regular user accounts on many Ubuntu installations.

 

 

24. Find Currently Logged-In Users

Use:

who

or:

w

or:

users

 

25. Find User's Groups

For devuser1:

groups devuser1

or:

id devuser1



 

🔥 Real-World Practice Scenario

Now let's combine everything.

Imagine you're a Linux System Administrator and your company has hired two developers.

Requirement

Create:

alice

bob

Create groups:

developers

devops

Your tasks

Task 1 — Create groups

sudo groupadd developers

sudo groupadd devops

Task 2 — Create users

sudo adduser alice

sudo adduser bob

Task 3 — Add Alice to developers

sudo usermod -aG developers alice

Task 4 — Add Bob to developers and devops

sudo usermod -aG developers,devops bob

Task 5 — Verify

id alice

id bob

Task 6 — Give Alice sudo access

sudo usermod -aG sudo alice

Task 7 — Lock Bob's account

sudo passwd -l bob

Task 8 — Unlock Bob

sudo passwd -u bob

Task 9 — Set Alice's password to expire

sudo chage -M 90 alice

Task 10 — Check

sudo chage -l alice

 

Beginner DevOps User Management Practice

I recommend practicing in this order:

Level

Practice

🟢 1

whoami, id, who, w

🟢 2

Create users

🟢 3

Delete users

🟢 4

Change passwords

🟢 5

Create groups

🟡 6

Add/remove users from groups

🟡 7

Sudo permissions

🟡 8

Lock/unlock accounts

🟡 9

Change username

🟡 10

Change shell

🟠 11

Password aging

🟠 12

Account expiration

🔴 13

/etc/passwd and /etc/shadow

🔴 14

Sudoers configuration

🔴 15

Real-world user-management scenarios

Your first lab

Since you're using WSL Ubuntu, start with just these commands:

whoami

id

sudo adduser devuser1

sudo adduser devuser2

sudo groupadd developers

sudo usermod -aG developers devuser1

sudo usermod -aG developers devuser2

id devuser1

id devuser2

groups devuser1

groups devuser2

Don't worry about memorizing the commands. For DevOps, understanding what each command does and when to use it is more important.

If you want to practice seriously, I can also give you a 30-day Ubuntu Linux practical lab, covering users groups permissions files processes services networking SSH packages cron logs, with daily tasks and interview questions.

 

No comments:

Post a Comment

Linux File Management & Text Processing — Beginner Guide

File management and text processing are core Linux skills for a System Administrator, Cloud Engineer, DevOps Engineer, and Linux Administra...