Linux Users and Groups: useradd, usermod, userdel, passwd, groups and id Explained
Every person and every program on Linux runs as a user. Users are put into groups so you can give the same rights to many people at once. In this chapter you learn where users live (/etc/passwd, /etc/shadow, /etc/group) and every command to create, change, lock and delete them.
What you'll learn in this chapter
- Know who you are with whoami, id and groups
- Read /etc/passwd, /etc/shadow and /etc/group
- Create users with useradd and set passwords with passwd
- Change users with usermod (-aG, -L, -s) and remove them with userdel
- Manage groups with groupadd, gpasswd and groupdel
- Control password age with chage and switch users with su
1. An everyday example: a housing society
Why do we need this?
In Kothrud, the Shanti housing society gives each resident a member card with a number. The secretary keeps the member register. Passwords for the society office locker are kept in a separate sealed book that only the secretary can open. Residents are grouped: committee, gym members, parking holders. A new tenant gets a card, is added to the gym group, and when they leave the card is cancelled.
What is it?
Member card number = UID. Member register = /etc/passwd. Sealed password book = /etc/shadow. Committee, gym, parking = groups in /etc/group. Giving a card = useradd. Adding to gym = usermod -aG gym. Cancelling the card = userdel. Secretary = root.
How to do it (step by step)
2. whoami: which user am I?
Why do we need this?
Before you run a risky command you must know if you are root or a normal user. Scripts also check this.
What is it?
whoami prints the name of the user you are running as now. It changes after sudo or su.
How to do it (step by step)
- Check your user.
whoami
Output:
ravi
What it means: You are logged in as ravi.
- See the change with sudo.
sudo whoami
Output:
root
What it means: sudo runs the command as root.
- Use it in a script check.
[ "$(whoami)" = root ] || echo 'Run as root'
Output:
Run as root
What it means: The script stops normal users.
3. id: UID, GID and all groups
Why do we need this?
Permission problems are almost always about which UID and groups you have. id shows them in one line.
What is it?
id shows uid (user number), gid (primary group) and groups (all groups). id NAME shows another user. -u prints only the UID, -g only the GID, -G all group numbers, -n gives names.
| Option | Shows |
|---|---|
| id | Everything |
| id -u | UID number |
| id -un | User name |
| id -gn | Primary group name |
| id -Gn | All group names |
How to do it (step by step)
- Show your identity.
id
Output:
uid=1001(ravi) gid=1001(ravi) groups=1001(ravi),10(wheel),992(docker)
What it means: ravi is in wheel (sudo) and docker.
- Check another user.
id nginx
Output:
uid=992(nginx) gid=990(nginx) groups=990(nginx)
What it means: A system user for the web server.
- Only the UID.
id -u
Output:
1001
What it means: Normal users start at 1000 on most systems.
- All group names.
id -Gn ravi
Output:
ravi wheel docker
What it means: Same as the groups command.
4. groups: list a user's groups
Why do we need this?
You added a user to a group but access still fails. First check the group list.
What is it?
groups prints the groups of the current shell. groups NAME reads the files and shows the saved list. New groups appear in your shell only after you log out and in again, or run newgrp.
How to do it (step by step)
- Your groups.
groups
Output:
ravi wheel
What it means: docker is missing in this old shell.
- Saved groups for ravi.
groups ravi
Output:
ravi : ravi wheel docker
What it means: The file already has docker.
- Load a new group now.
newgrp docker && id -Gn
Output:
docker ravi wheel
What it means: No need to log out.
5. /etc/passwd: the user list
Why do we need this?
When a login fails or a service user looks wrong, you read this file to see the home folder, shell and UID.
What is it?
Each line has 7 fields split by ':' — name:x:UID:GID:comment:home:shell. The x means the password is in /etc/shadow. Shell /sbin/nologin blocks interactive login. Everyone can read this file. Use getent passwd NAME to also see users from LDAP or AD.
| Field | Example | Meaning |
|---|---|---|
| 1 | ravi | Login name |
| 2 | x | Password is in shadow |
| 3 | 1001 | UID |
| 4 | 1001 | Primary GID |
| 5 | Ravi B | Comment (GECOS) |
| 6 | /home/ravi | Home folder |
| 7 | /bin/bash | Login shell |
How to do it (step by step)
- See one user's line.
grep '^ravi:' /etc/passwd
Output:
ravi:x:1001:1001:Ravi B:/home/ravi:/bin/bash
What it means: Name, UID 1001, home and bash shell.
- Same with getent (works with LDAP too).
getent passwd nginx
Output:
nginx:x:992:990:Nginx web server:/var/lib/nginx:/sbin/nologin
What it means: nologin: no one can log in as nginx.
- List only real users (UID 1000+).
awk -F: '$3>=1000 && $3<65534 {print $1}' /etc/passwd
Output:
ravi
priya
anil
What it means: Field 3 is the UID.
- Who has UID 0?
awk -F: '$3==0 {print $1}' /etc/passwd
Output:
root
What it means: Any other name here is a security alarm.
6. /etc/shadow: hidden passwords and ageing
Why do we need this?
You need to check if an account is locked or when its password expires.
What is it?
Only root can read /etc/shadow. Fields: name:hash:lastchange:min:max:warn:inactive:expire. A hash starting with $6$ is SHA-512, $y$ is yescrypt. ! or !! at the start means locked or no password set. passwd -S shows a short status.
How to do it (step by step)
- Normal users cannot read it.
cat /etc/shadow
Output:
cat: /etc/shadow: Permission denied
What it means: Good. Hashes stay secret.
- Read one line as root.
sudo grep '^priya:' /etc/shadow
Output:
priya:$y$j9T$Kd...:20386:0:90:7:::
What it means: Password changed on day 20386, max age 90 days, warn 7 days before.
- A locked account.
sudo grep '^anil:' /etc/shadow | cut -c1-12
Output:
anil:!$y$j9T
What it means: The ! means the password is locked.
7. /etc/group and /etc/gshadow: group lists
Why do we need this?
To know who is in the docker, wheel or finance group, you read the group file.
What is it?
Each line is group:x:GID:member1,member2. Members listed here have it as a secondary group. A user's primary group is in field 4 of /etc/passwd and is often not listed again. getent group NAME is the safe way to read it.
How to do it (step by step)
- Members of wheel.
getent group wheel
Output:
wheel:x:10:ravi,priya
What it means: ravi and priya can use sudo (Red Hat family).
- Ubuntu uses sudo group.
getent group sudo
Output:
sudo:x:27:ubuntu,ravi
What it means: Same idea, different name.
- Count groups on the system.
wc -l < /etc/group
Output:
58
What it means: Most are system groups.
8. useradd: create a user
Why do we need this?
A new developer, an app account or a CI runner needs its own login so actions are tracked and rights are separate.
What is it?
useradd NAME creates the user. Key options: -m make home folder, -d set home path, -s login shell, -c comment, -u fixed UID, -g primary group, -G extra groups, -r system user (low UID, no home by default), -e expiry date. Defaults come from /etc/default/useradd and /etc/login.defs. On Ubuntu, adduser is a friendly wrapper that asks questions.
| Option | Meaning |
|---|---|
| -m | Create home folder |
| -s /bin/bash | Login shell |
| -G a,b | Extra groups |
| -c 'text' | Full name or note |
| -u 1500 | Fixed UID |
| -r | System user |
| -e 2026-12-31 | Account expiry |
How to do it (step by step)
- Create a normal user with home and bash.
sudo useradd -m -s /bin/bash -c 'Priya Kulkarni' priya && getent passwd priya
Output:
priya:x:1002:1002:Priya Kulkarni:/home/priya:/bin/bash
What it means: -m made /home/priya with files from /etc/skel.
- Create a user with extra groups.
sudo useradd -m -G wheel,docker anil && id anil
Output:
uid=1003(anil) gid=1003(anil) groups=1003(anil),10(wheel),992(docker)
What it means: anil gets sudo and docker on day one.
- A system user for an app (no login).
sudo useradd -r -s /sbin/nologin -d /opt/billing billing && getent passwd billing
Output:
billing:x:989:987::/opt/billing:/sbin/nologin
What it means: Low UID, cannot log in. Safe for services.
- A contractor account that expires.
sudo useradd -m -e 2026-12-31 vendor1 && sudo chage -l vendor1 | grep 'Account expires'
Output:
Account expires : Dec 31, 2026
What it means: The account stops working after that date.
- See the defaults.
useradd -D
Output:
GROUP=100
HOME=/home
SHELL=/bin/bash
SKEL=/etc/skel
What it means: Used when you skip options.
9. passwd: set, lock and check passwords
Why do we need this?
A new user cannot log in until a password (or SSH key) is set. You also lock accounts when someone leaves.
What is it?
passwd changes your own password. sudo passwd NAME sets another user's. -l lock, -u unlock, -S status, -e expire now (force change at next login), -d delete password (dangerous). To set from a script use echo 'name:pass' | sudo chpasswd.
How to do it (step by step)
- Set a password for priya.
sudo passwd priya
Output:
New password:
Retype new password:
passwd: password updated successfully
What it means: Typing is hidden on screen.
- Force change at first login.
sudo passwd -e priya
Output:
Expiring password for user priya.
passwd: Success
What it means: She must pick her own password.
- Lock and check.
sudo passwd -l anil && sudo passwd -S anil
Output:
Locking password for user anil.
passwd: Success
anil LK 2026-10-25 0 99999 7 -1
What it means: LK means locked. SSH keys may still work, so also expire the account.
- Set many passwords from a file.
sudo chpasswd < new-users.txt
Output:
(no output)
What it means: Each line is name:password.
10. usermod: change an existing user
Why do we need this?
People change teams, need docker access, change their shell or must be locked out. usermod does all of this without recreating the user.
What is it?
-aG GROUP append a group (ALWAYS use -a with -G, or other groups are removed). -g new primary group, -s shell, -d -m move home, -l new login name, -L lock, -U unlock, -e expiry date, -c comment.
| Option | Meaning |
|---|---|
| -aG docker | Add to docker, keep others |
| -G docker | Set ONLY docker (removes others) |
| -s /bin/zsh | Change shell |
| -L / -U | Lock / unlock |
| -l new | Rename login |
| -e DATE | Expire on date |
How to do it (step by step)
- Add ravi to docker safely.
sudo usermod -aG docker ravi && groups ravi
Output:
ravi : ravi wheel docker
What it means: wheel stayed because of -a.
- The common mistake.
sudo usermod -G docker ravi && groups ravi
Output:
ravi : ravi docker
What it means: Without -a, wheel was removed and ravi lost sudo.
- Change the shell.
sudo usermod -s /bin/zsh priya && getent passwd priya | cut -d: -f7
Output:
/bin/zsh
What it means: Field 7 changed.
- Lock an employee who left.
sudo usermod -L -e 1 anil && sudo chage -l anil | grep 'Account expires'
Output:
Account expires : Jan 02, 1970
What it means: -L locks the password, -e 1 expires the account so SSH keys stop too.
- Rename a login and move home.
sudo usermod -l priyak -d /home/priyak -m priya && ls /home
Output:
anil priyak ravi
What it means: UID stays the same, files stay owned.
11. userdel: remove a user
Why do we need this?
Old accounts are a security risk. When someone leaves for good, remove the account.
What is it?
userdel NAME removes the account but keeps the home folder. -r also deletes home and mail spool. Files elsewhere stay with the old UID (find them with find / -nouser). Kill the user's processes first, or userdel fails with 'user is currently used by process'.
How to do it (step by step)
- Back up, then delete with home.
sudo tar czf /root/anil-home.tgz /home/anil && sudo userdel -r anil
Output:
userdel: anil mail spool (/var/mail/anil) not found
What it means: Just a note; the user and home are gone.
- When the user is still logged in.
sudo userdel vendor1
Output:
userdel: user vendor1 is currently used by process 4312
What it means: Stop their processes first.
- Stop processes, then delete.
sudo pkill -u vendor1; sudo userdel -r vendor1 && id vendor1
Output:
id: 'vendor1': no such user
What it means: The account is gone.
- Find leftover files.
sudo find / -xdev -nouser 2>/dev/null
Output:
/srv/share/report-anil.xlsx
What it means: Give them a new owner with chown.
12. groupadd, groupmod, groupdel: manage groups
Why do we need this?
Teams share folders. A group like finance or devs lets you give rights once to the whole team.
What is it?
groupadd NAME creates a group (-g sets GID, -r system group). groupmod -n NEW OLD renames, -g changes GID. groupdel NAME removes it (it cannot be any user's primary group).
How to do it (step by step)
- Create a team group.
sudo groupadd -g 3000 finance && getent group finance
Output:
finance:x:3000:
What it means: Empty group with GID 3000.
- Rename it.
sudo groupmod -n accounts finance && getent group accounts
Output:
accounts:x:3000:
What it means: GID and file ownership stay.
- Delete a group.
sudo groupdel accounts
Output:
(no output)
What it means: Files with GID 3000 now show just the number.
13. gpasswd: add or remove group members
Why do we need this?
usermod -aG adds one user to many groups. gpasswd is easier to add or remove one member from one group.
What is it?
gpasswd -a USER GROUP adds, -d USER GROUP removes, -M u1,u2 GROUP sets the full member list, -A sets group admins.
How to do it (step by step)
- Add a member.
sudo gpasswd -a priya devs
Output:
Adding user priya to group devs
What it means: Same as usermod -aG devs priya.
- Remove a member.
sudo gpasswd -d ravi docker
Output:
Removing user ravi from group docker
What it means: Only docker is removed.
- Set the whole list.
sudo gpasswd -M ravi,priya devs && getent group devs
Output:
devs:x:3001:ravi,priya
What it means: Anyone else is dropped.
14. chage: password and account ageing
Why do we need this?
Company policy says passwords expire every 90 days, and contractor accounts expire on a date.
What is it?
chage -l USER lists ageing. -M max days, -m min days, -W warn days, -I inactive days after expiry, -E expiry date (YYYY-MM-DD, -1 for never), -d 0 forces change at next login. System defaults are PASS_MAX_DAYS etc. in /etc/login.defs.
How to do it (step by step)
- See the ageing.
sudo chage -l priya
Output:
Last password change : Oct 25, 2026
Password expires : never
Account expires : never
What it means: No policy yet.
- Apply a 90 day policy.
sudo chage -M 90 -m 1 -W 7 priya && sudo chage -l priya | grep 'Password expires'
Output:
Password expires : Jan 23, 2027
What it means: 90 days from the last change.
- Force a change now.
sudo chage -d 0 priya
Output:
(no output)
What it means: At next login she must set a new password.
- Remove expiry.
sudo chage -E -1 vendor1
Output:
(no output)
What it means: -1 means never expires.
15. su: switch to another user
Why do we need this?
You need to test what a service user can see, or work as another user for a while.
What is it?
su - USER starts a full login shell as USER (asks USER's password). The - loads their environment and home. su without a name means root. sudo su - or sudo -iu USER uses your own password instead. -c runs one command. -s gives a shell to a nologin user.
How to do it (step by step)
- Become priya.
su - priya
Output:
Password:
[priya@web1 ~]$
What it means: Prompt shows the new user. Type exit to go back.
- Run one command as a service user.
sudo su -s /bin/bash -c 'ls /var/lib/nginx' nginx
Output:
body proxy tmp
What it means: Tests what nginx can read.
- Why the dash matters.
su priya -c pwd; su - priya -c pwd
Output:
/home/ravi
/home/priya
What it means: Without - you keep the old folder and environment.
16. who, w and last: who is logged in
Why do we need this?
Before a reboot, or during a security check, you need to know who is on the server and who logged in recently.
What is it?
who lists current logins. w also shows what each person is running and load. last shows login history from /var/log/wtmp; lastb shows failed logins (root only). lastlog shows the last login for every user.
How to do it (step by step)
- Who is on now?
who
Output:
ravi pts/0 2026-10-25 09:12 (49.36.10.4)
priya pts/1 2026-10-25 10:02 (103.21.5.9)
What it means: Two people are connected over SSH.
- What are they doing?
w -h
Output:
ravi pts/0 49.36.10.4 09:12 0.00s bash
priya pts/1 103.21.5.9 10:02 2:10 vim app.conf
What it means: Warn priya before restarting.
- Recent logins.
last -n 3
Output:
priya pts/1 103.21.5.9 Sun Oct 25 10:02 still logged in
ravi pts/0 49.36.10.4 Sun Oct 25 09:12 still logged in
reboot system boot 5.14.0 Sat Oct 24 22:01
What it means: Includes reboots.
- Failed logins.
sudo lastb -n 2
Output:
admin ssh:notty 185.220.1.9 Sun Oct 25 03:11 - 03:11
root ssh:notty 185.220.1.9 Sun Oct 25 03:11 - 03:11
What it means: Bots guessing passwords. Use keys and fail2ban.
17. Real examples from many industries
Why do we need this?
The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.
What is it?
Each row is a made-up team. It shows who uses this and how.
How to do it (step by step)
| Team and city | How they use it | Command |
|---|---|---|
| Sneha, IT admin, Pune | Creates accounts for new joiners with home and groups | useradd -m -s /bin/bash -G devs NAME |
| Omar, hospital IT, Dubai | Locks accounts of staff who leave the same day | usermod -L -e 1 NAME |
| Lucy, bank compliance, London | Enforces 90 day password ageing | chage -M 90 -W 7 NAME |
| Arjun, SaaS DevOps, Bengaluru | Gives the deploy user docker access | usermod -aG docker deploy |
| Mei, university lab, Singapore | Creates 60 student accounts from a file | newusers students.txt |
| Carlos, retail ops, Mexico City | Runs apps as system users without login | useradd -r -s /sbin/nologin pos |
18. Common errors and how to fix them
Why do we need this?
Everyone hits these errors. Knowing the cause saves hours.
What is it?
Read the exact message first. Then match it to a row below.
How to do it (step by step)
| Error you see | Why it happens | How to fix |
|---|---|---|
useradd: user 'priya' already exists | The name is taken | Pick another name or change the existing user with usermod.getent passwd priya |
useradd: Permission denied. | Normal users cannot create users | Run with sudo.sudo useradd -m priya |
usermod: group 'dockr' does not exist | Typo or the group is not created | Check the name or create it.getent group docker |
User lost sudo after usermod -G | -G without -a replaced all groups | Add back with -aG.sudo usermod -aG wheel ravi |
permission denied while trying to connect to the Docker daemon socket | New group not active in the old shell | Log out and in, or newgrp.newgrp docker |
userdel: user vendor1 is currently used by process 4312 | The user still has running processes | Stop them first.sudo pkill -u vendor1 |
su: Authentication failure | Wrong password, or root has no password (Ubuntu) | Use sudo -i with your own password.sudo -i |
This account is currently not available. | Shell is /sbin/nologin | Expected for service users; use -s to test.sudo su -s /bin/bash -c id nginx |
passwd: Authentication token manipulation error | Disk full, read-only root, or /etc/shadow locked | Check df -h and mount; remove stale lock files.df -h /; ls /etc/*.lock |
Your account has expired; please contact your system administrator | Account expiry date passed | Extend with chage -E.sudo chage -E 2027-03-31 vendor1 |
19. Troubleshooting step by step
Why do we need this?
When a user cannot log in or cannot access something, check identity, account state and groups in this order.
What is it?
Go top to bottom. Stop at the first step that shows the problem.
How to do it (step by step)
- Does the user exist?
getent passwd priya
- Is the shell a real shell?
getent passwd priya | cut -d: -f7
- Is the password locked or expired?
sudo passwd -S priya; sudo chage -l priya
- Which groups does the user have?
id priya
- Did the group change need a new login?
sudo -iu priya id -Gn
- Check the auth log.
sudo journalctl -u sshd --since '10 min ago' | tail
20. Lab 1: Onboard and offboard an employee
Why do we need this?
Create a user with groups and a forced password change, then lock and remove them safely.
What is it?
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
How to do it (step by step)
- Create a team group.
sudo groupadd devs && getent group devs
Output:
devs:x:3001:
- Create the user.
sudo useradd -m -s /bin/bash -c 'Lab User' -G devs labuser && id labuser
Output:
uid=1004(labuser) gid=1004(labuser) groups=1004(labuser),3001(devs)
- Set a password and force change.
echo 'labuser:Temp@12345' | sudo chpasswd && sudo chage -d 0 labuser && sudo chage -l labuser | head -2
Output:
Last password change : password must be changed
Password expires : password must be changed
- Lock the user on the last day.
sudo usermod -L -e 1 labuser && sudo passwd -S labuser
Output:
labuser LK 1970-01-01 0 99999 7 -1
- Back up home and delete.
sudo tar czf /root/labuser.tgz /home/labuser && sudo userdel -r labuser && id labuser
Output:
id: 'labuser': no such user
21. Lab 2: Read the user databases
Why do we need this?
Use awk and getent to answer real admin questions from /etc/passwd and /etc/group.
What is it?
A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).
How to do it (step by step)
- List human users.
awk -F: '$3>=1000 && $3<65534 {print $1, $6}' /etc/passwd
Output:
ravi /home/ravi
priya /home/priya
- Users who can log in.
grep -v -E 'nologin|false' /etc/passwd | cut -d: -f1
Output:
root
ravi
priya
- Check for extra UID 0.
awk -F: '$3==0' /etc/passwd
Output:
root:x:0:0:root:/root:/bin/bash
- Who can use sudo?
getent group wheel sudo
Output:
wheel:x:10:ravi,priya
- Accounts with no password set.
sudo awk -F: '$2=="" {print $1}' /etc/shadow
Output:
(no output)
Ravindra Bagale's Tip
Always use usermod -aG (with -a) to add a group. Plain -G silently removes every other group, and people lose sudo or docker. After adding a group, the user must log in again before it works.
Ravindra Bagale's Tip – मराठी
Group जोडायला नेहमी usermod -aG (-a सह). फक्त -G बाकी सगळे groups शांतपणे काढतो, आणि लोकांचं sudo किंवा docker जातं. Group जोडल्यावर user ने परत login केल्यावरच तो चालतो.
Ravindra Bagale's Tip – हिंदी
Group जोड़ने के लिए हमेशा usermod -aG (-a के साथ) लगाएं. सिर्फ -G बाकी सारे groups चुपचाप हटा देता है, और लोगों का sudo या docker चला जाता है. Group जोड़ने के बाद user को दोबारा login करना पड़ता है.
22. Frequently asked questions
Q. useradd or adduser?
useradd works the same on every distro. adduser (Debian/Ubuntu) is an interactive helper that creates the home and asks for a password.
Q. What is the difference between primary and secondary groups?
The primary group (field 4 of /etc/passwd) owns new files you create. Secondary groups give extra access.
Q. Why is the password field 'x'?
Hashes moved to /etc/shadow, which only root can read.
Q. What UID do normal users get?
Usually 1000 and up (UID_MIN in /etc/login.defs). System users are below that.
Q. Does passwd -l stop SSH key logins?
No. Also expire the account (usermod -e 1) or remove the key.
Q. Can I edit /etc/passwd by hand?
Use vipw or vigr if you must; they lock the file. Prefer useradd and usermod.
Q. Why do my new groups not show?
Groups load at login. Log out and back in, or use newgrp.
Q. Where do new home files come from?
From /etc/skel. Put a default .bashrc there for all new users.
23. Interview questions and answers
Beginner level
Q. How do you see your UID and groups?
id.
Q. Where are user accounts stored?
/etc/passwd, passwords in /etc/shadow, groups in /etc/group.
Q. How do you create a user with a home folder?
sudo useradd -m NAME, then sudo passwd NAME.
Q. What is UID 0?
root, the super user.
Mid level level
Q. How do you add a user to docker without removing other groups?
sudo usermod -aG docker USER, then log in again.
Q. How do you lock a user completely?
usermod -L to lock the password and usermod -e 1 (or chage -E 0) to expire the account; also remove SSH keys.
Q. What is a system user?
An account for a service with a low UID and usually /sbin/nologin, created with useradd -r.
Q. How do you force a password change at next login?
chage -d 0 USER or passwd -e USER.
Senior level
Q. Users exist in LDAP, but getent passwd does not show them. What do you check?
nsswitch.conf (passwd: files sss), sssd status and logs, network to the directory, and cache (sss_cache -E).
Q. Same user has different UIDs on two servers sharing NFS. What happens and how do you fix it?
Files show wrong owners. Use central identity (LDAP/IPA/AD) or fixed UIDs with useradd -u, then chown files to the right UID.
Q. How would you offboard an engineer across 200 servers?
Disable in the central directory, revoke SSH keys and sudo rules via config management, expire local accounts, rotate shared secrets, and audit with last and find -user.
Q. Why is a second UID 0 account dangerous even with another name?
Linux checks the number, so it is full root and easy to miss in audits.
Try at home
- On a test machine, create user 'guest1' with a home folder, add it to a new group 'readers', set a password that must be changed at first login, then lock and delete it.
- Use awk on /etc/passwd to print every user whose shell is /bin/bash.
Practice Tasks
Maple Leaf Books is a bookselling business in Toronto. Emily Tremblay looks after its IT and cloud work. They count money in CAD and run their AWS resources in the ca-central-1 Region. In the tasks below you do real jobs for them using what this lesson teaches. All names, account IDs, IP addresses and numbers are made up for practice.
0 / 17
Easy My primary group
Why: Check before running admin work.
What to do: Emily Tremblay at Maple Leaf Books wants to print only the name of user kavya's primary group.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy UID and groups
Why: Access problems start with groups.
What to do: Show the UID, GID and groups of user kavya.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Only group names
Why: Quick check of membership.
What to do: List only the group names of user deploy.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Create a user with home
Why: New joiner at BIZ.
What to do: Create user nikhil with a home folder.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Set a password
Why: A new user needs a password.
What to do: Set the password of user nikhil (as root).
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Create a group
Why: Teams share files through groups.
What to do: Create a group named finance.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Easy Recent logins
Why: Who logged in after the incident?
What to do: Show the last 5 logins.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Look up a user entry
Why: Works for local and LDAP users.
What to do: Print the passwd entry for user ravi using the name service lookup tool.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium User with shell and groups
Why: Developers need bash and the devs group.
What to do: Create user asha with a home, bash as shell and extra group devs.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium System user for a service
Why: Services must not log in.
What to do: Create a system user named appsvc with no login shell (/sbin/nologin).
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Force change at next login
Why: Temporary passwords must be changed.
What to do: Expire the password of nikhil so he must change it at next login.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Add to a group safely
Why: Without -a, other groups are removed.
What to do: Add user priya to the docker group without removing her other groups.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Lock an account
Why: Someone is on long leave.
What to do: Lock the account of user rahul with usermod.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Remove a user and home
Why: Leaver cleanup.
What to do: Delete user intern1 together with the home folder.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium See password ageing
Why: Audits ask for expiry.
What to do: List the password ageing details of user kavya.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Medium Become a user with login shell
Why: Test what deploy sees.
What to do: Switch to user deploy with a full login environment using su.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
Hard Max password age 90 days
Why: Policy at BIZ says 90 days.
What to do: Set the maximum password age of priya to 90 days.
- Find the Linux command that does this job.
- Add the options (like -r or -h) the task needs.
- Add the file names, folders or users in the right order.
- Use sudo if the job changes system files or users. Click Check answer.
24. Related chapters
- Linux Ops Refresh for DevOps
- Bash Scripting for Automation
- Linux grep and find Commands with Examples
- How to Set Up Passwordless SSH Between Linux Servers
In short
- whoami, id and groups show who you are.
- /etc/passwd 7 fields; hashes in /etc/shadow; groups in /etc/group.
- useradd -m -s -G -r -e creates users.
- usermod -aG adds a group; never plain -G.
- passwd -l, usermod -L -e 1 and userdel -r offboard users.
- chage sets ageing; su - switches users; last shows history.
Revision, comparison and interview cards
Revise this lesson in a few minutes. Save the cards on your phone or download them as PNG files. The QR code on each card opens this lesson.








More cards: Ravi Sir's Cards.