Ravindra BagaleCourses & study guides मराठी Track your progress

AWS Cloud

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.

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

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.

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 Linux knows who you areYou log in with a name and passwordLinux finds the name in /etc/passwd and gets the UIDIt checks the password hash in /etc/shadowIt reads your groups from /etc/groupYour shell starts with that UID and those groupsEvery file access is checked against UID and groups
Linux cares about numbers (UID, GID), not names. Names are only labels.

2. whoami: which user am I?

Before you run a risky command you must know if you are root or a normal user. Scripts also check this.

whoami prints the name of the user you are running as now. It changes after sudo or su.

  1. Check your user.
whoami

Output:

ravi

You are logged in as ravi.

  1. See the change with sudo.
sudo whoami

Output:

root

sudo runs the command as root.

  1. Use it in a script check.
[ "$(whoami)" = root ] || echo 'Run as root'

Output:

Run as root

The command prints a warning for a non-root user. It does not stop the script.

3. id: UID, GID and all groups

Linux permission checks use numbers. A UID identifies a user, a primary GID identifies its main group, and supplementary GIDs define additional group memberships. Display names in id make these numbers easier to recognize. On a shared disk, two machines with the same name for a group still need compatible numerical IDs to agree on ordinary group ownership.

In a practice machine, inspect id from a normal login and compare it with the name and permissions of a sample file from ls -l. Read the owner, group and access bits before changing anything. Adding a group changes the account setup, while a running shell already holds a set of process credentials. Check a fresh login for the updated group before editing a file’s ownership or widening permissions.

Permission problems are almost always about which UID and groups you have. id shows them in one line.

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.

OptionShows
idEverything
id -uUID number
id -unUser name
id -gnPrimary group name
id -GnAll group names
  1. Show your identity.
id

Output:

uid=1001(ravi) gid=1001(ravi) groups=1001(ravi),10(wheel),992(docker)

ravi is in wheel (sudo) and docker.

  1. Check another user.
id nginx

Output:

uid=992(nginx) gid=990(nginx) groups=990(nginx)

A system user for the web server.

  1. Only the UID.
id -u

Output:

1001

Normal users start at 1000 on most systems.

  1. All group names.
id -Gn ravi

Output:

ravi wheel docker

Same as the groups command.

4. groups: list a user's groups

You added a user to a group but access still fails. First check the group list.

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.

  1. Your groups.
groups

Output:

ravi wheel

docker is missing in this old shell.

  1. Saved groups for ravi.
groups ravi

Output:

ravi : ravi wheel docker

The file already has docker.

  1. Load a new group now.
newgrp docker && id -Gn

Output:

docker ravi wheel

No need to log out.

5. /etc/passwd: the user list

When a login fails or a service user looks wrong, you read this file to see the home folder, shell and UID.

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.

FieldExampleMeaning
1raviLogin name
2xPassword is in shadow
31001UID
41001Primary GID
5Ravi BComment (GECOS)
6/home/raviHome folder
7/bin/bashLogin shell
  1. See one user's line.
grep '^ravi:' /etc/passwd

Output:

ravi:x:1001:1001:Ravi B:/home/ravi:/bin/bash

Name, UID 1001, home and bash shell.

  1. Same with getent (works with LDAP too).
getent passwd nginx

Output:

nginx:x:992:990:Nginx web server:/var/lib/nginx:/sbin/nologin

nologin: no one can log in as nginx.

  1. List only real users (UID 1000+).
awk -F: '$3>=1000 && $3<65534 {print $1}' /etc/passwd

Output:

ravi
priya
anil

Field 3 is the UID.

  1. Who has UID 0?
awk -F: '$3==0 {print $1}' /etc/passwd

Output:

root

Any other name here is a security alarm.

6. /etc/shadow: hidden passwords and ageing

You need to check if an account is locked or when its password expires.

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.

  1. Normal users cannot read it.
cat /etc/shadow

Output:

cat: /etc/shadow: Permission denied

Good. Hashes stay secret.

  1. Read one line as root.
sudo grep '^priya:' /etc/shadow

Output:

priya:$y$j9T$Kd...:20386:0:90:7:::

Password changed on day 20386, max age 90 days, warn 7 days before.

  1. A locked account.
sudo grep '^anil:' /etc/shadow | cut -c1-12

Output:

anil:!$y$j9T

The ! means the password is locked.

7. /etc/group and /etc/gshadow: group lists

To know who is in the docker, wheel or finance group, you read the group file.

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.

  1. Members of wheel.
getent group wheel

Output:

wheel:x:10:ravi,priya

ravi and priya can use sudo (Red Hat family).

  1. Ubuntu uses sudo group.
getent group sudo

Output:

sudo:x:27:ubuntu,ravi

Same idea, different name.

  1. Count groups on the system.
wc -l < /etc/group

Output:

58

Most are system groups.

8. useradd: create a user

A new developer, an app account or a CI runner needs its own login so actions are tracked and rights are separate.

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.

OptionMeaning
-mCreate home folder
-s /bin/bashLogin shell
-G a,bExtra groups
-c 'text'Full name or note
-u 1500Fixed UID
-rSystem user
-e 2026-12-31Account expiry
  1. 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

-m made /home/priya with files from /etc/skel.

  1. 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)

anil gets sudo and docker on day one.

  1. 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

Low UID, cannot log in. Safe for services.

  1. 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

The account stops working after that date.

  1. See the defaults.
useradd -D

Output:

GROUP=100
HOME=/home
SHELL=/bin/bash
SKEL=/etc/skel

Used when you skip options.

9. passwd: set, lock and check passwords

A new user cannot log in until a password (or SSH key) is set. You also lock accounts when someone leaves.

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.

  1. Set a password for priya.
sudo passwd priya

Output:

New password:
Retype new password:
passwd: password updated successfully

Typing is hidden on screen.

  1. Force change at first login.
sudo passwd -e priya

Output:

Expiring password for user priya.
passwd: Success

She must pick her own password.

  1. 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

LK means locked. SSH keys may still work, so also expire the account.

  1. Set many passwords from a file.
sudo chpasswd < new-users.txt

Output:

(no output)

Each line is name:password.

10. usermod: change an existing user

People change teams, need docker access, change their shell or must be locked out. usermod does all of this without recreating the user.

-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.

After adding asha to reports, compare id asha with plain id inside her original login shell. The first checks the account’s configured groups, while the second shows the groups held by the running process. Start a fresh login and check again before changing the report directory’s permissions.

OptionMeaning
-aG dockerAdd to docker, keep others
-G dockerSet ONLY docker (removes others)
-s /bin/zshChange shell
-L / -ULock / unlock
-l newRename login
-e DATEExpire on date
  1. Add ravi to docker safely.
sudo usermod -aG docker ravi && groups ravi

Output:

ravi : ravi wheel docker

wheel stayed because of -a.

  1. The common mistake.
sudo usermod -G docker ravi && groups ravi

Output:

ravi : ravi docker

Without -a, wheel was removed and ravi lost sudo.

  1. Change the shell.
sudo usermod -s /bin/zsh priya && getent passwd priya | cut -d: -f7

Output:

/bin/zsh

Field 7 changed.

  1. Lock an employee who left.
sudo usermod -L -e 1 anil && sudo chage -l anil | grep 'Account expires'

Output:

Account expires : Jan 02, 1970

-L locks the password, -e 1 expires the account so SSH keys stop too.

  1. Rename a login and move home.
sudo usermod -l priyak -d /home/priyak -m priya && ls /home

Output:

anil  priyak  ravi

UID stays the same, files stay owned.

11. userdel: remove a user

Old accounts are a security risk. When someone leaves for good, remove the account.

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'.

  1. 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

Just a note; the user and home are gone.

  1. When the user is still logged in.
sudo userdel vendor1

Output:

userdel: user vendor1 is currently used by process 4312

Stop their processes first.

  1. Stop processes, then delete.
sudo pkill -u vendor1; sudo userdel -r vendor1 && id vendor1

Output:

id: 'vendor1': no such user

The account is gone.

  1. Find leftover files.
sudo find / -xdev -nouser 2>/dev/null

Output:

/srv/share/report-anil.xlsx

Give them a new owner with chown.

12. groupadd, groupmod, groupdel: manage groups

Teams share folders. A group like finance or devs lets you give rights once to the whole team.

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).

  1. Create a team group.
sudo groupadd -g 3000 finance && getent group finance

Output:

finance:x:3000:

Empty group with GID 3000.

  1. Rename it.
sudo groupmod -n accounts finance && getent group accounts

Output:

accounts:x:3000:

GID and file ownership stay.

  1. Delete a group.
sudo groupdel accounts

Output:

(no output)

Files with GID 3000 now show just the number.

13. gpasswd: add or remove group members

usermod -aG adds one user to many groups. gpasswd is easier to add or remove one member from one group.

gpasswd -a USER GROUP adds, -d USER GROUP removes, -M u1,u2 GROUP sets the full member list, -A sets group admins.

  1. Add a member.
sudo gpasswd -a priya devs

Output:

Adding user priya to group devs

Same as usermod -aG devs priya.

  1. Remove a member.
sudo gpasswd -d ravi docker

Output:

Removing user ravi from group docker

Only docker is removed.

  1. Set the whole list.
sudo gpasswd -M ravi,priya devs && getent group devs

Output:

devs:x:3001:ravi,priya

Anyone else is dropped.

14. chage: password and account ageing

Company policy says passwords expire every 90 days, and contractor accounts expire on a date.

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.

  1. See the ageing.
sudo chage -l priya

Output:

Last password change : Oct 25, 2026
Password expires : never
Account expires : never

No policy yet.

  1. 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

90 days from the last change.

  1. Force a change now.
sudo chage -d 0 priya

Output:

(no output)

At next login she must set a new password.

  1. Remove expiry.
sudo chage -E -1 vendor1

Output:

(no output)

-1 means never expires.

15. su: switch to another user

You need to test what a service user can see, or work as another user for a while.

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.

  1. Become priya.
su - priya

Output:

Password:
[priya@web1 ~]$

Prompt shows the new user. Type exit to go back.

  1. Run one command as a service user.
sudo su -s /bin/bash -c 'ls /var/lib/nginx' nginx

Output:

body  proxy  tmp

Tests what nginx can read.

  1. Why the dash matters.
su priya -c pwd; su - priya -c pwd

Output:

/home/ravi
/home/priya

Without - you keep the old folder and environment.

16. who, w and last: who is logged in

Before a reboot, or during a security check, you need to know who is on the server and who logged in recently.

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.

  1. 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)

Two people are connected over SSH.

  1. 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

Warn priya before restarting.

  1. 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

Includes reboots.

  1. 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

Bots guessing passwords. Use keys and fail2ban.

17. Real examples from many industries

The same Linux skill shows up in every kind of company. Seeing it in many places helps you remember it.

Each row is a made-up team. It shows who uses this and how.

Team and cityHow they use itCommand
Sneha, IT admin, PuneCreates accounts for new joiners with home and groupsuseradd -m -s /bin/bash -G devs NAME
Omar, hospital IT, DubaiLocks accounts of staff who leave the same dayusermod -L -e 1 NAME
Lucy, bank compliance, LondonEnforces 90 day password ageingchage -M 90 -W 7 NAME
Arjun, SaaS DevOps, BengaluruGives the deploy user docker accessusermod -aG docker deploy
Mei, university lab, SingaporeCreates 60 student accounts from a filenewusers students.txt
Carlos, retail ops, Mexico CityRuns apps as system users without loginuseradd -r -s /sbin/nologin pos

18. Common errors and how to fix them

Everyone hits these errors. Knowing the cause saves hours.

Read the exact message first. Then match it to a row below.

Error you seeWhy it happensHow to fix
useradd: user 'priya' already existsThe name is takenPick another name or change the existing user with usermod.
getent passwd priya
useradd: Permission denied.Normal users cannot create usersRun with sudo.
sudo useradd -m priya
usermod: group 'dockr' does not existTypo or the group is not createdCheck the name or create it.
getent group docker
User lost sudo after usermod -G-G without -a replaced all groupsAdd back with -aG.
sudo usermod -aG wheel ravi
permission denied while trying to connect to the Docker daemon socketNew group not active in the old shellLog out and in, or newgrp.
newgrp docker
userdel: user vendor1 is currently used by process 4312The user still has running processesStop them first.
sudo pkill -u vendor1
su: Authentication failureWrong 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/nologinExpected for service users; use -s to test.
sudo su -s /bin/bash -c id nginx
passwd: Authentication token manipulation errorDisk full, read-only root, or /etc/shadow lockedCheck df -h and mount; remove stale lock files.
df -h /; ls /etc/*.lock
Your account has expired; please contact your system administratorAccount expiry date passedExtend with chage -E.
sudo chage -E 2027-03-31 vendor1

19. Troubleshooting step by step

When a user cannot log in or cannot access something, check identity, account state and groups in this order.

Go top to bottom. Stop at the first step that shows the problem.

  1. Does the user exist?
getent passwd priya
  1. Is the shell a real shell?
getent passwd priya | cut -d: -f7
  1. Is the password locked or expired?
sudo passwd -S priya; sudo chage -l priya
  1. Which groups does the user have?
id priya
  1. Did the group change need a new login?
sudo -iu priya id -Gn
  1. Check the auth log.
sudo journalctl -u sshd --since '10 min ago' | tail

20. Lab 1: Onboard and offboard an employee

Create a user with groups and a forced password change, then lock and remove them safely.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. Create a team group.
sudo groupadd devs && getent group devs

Output:

devs:x:3001:
  1. 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)
  1. 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
  1. 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
  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

Use awk and getent to answer real admin questions from /etc/passwd and /etc/group.

A full hands-on lab. Run every step on a test Linux machine (an EC2 instance, a VM, or WSL).

  1. List human users.
awk -F: '$3>=1000 && $3<65534 {print $1, $6}' /etc/passwd

Output:

ravi /home/ravi
priya /home/priya
  1. Users who can log in.
grep -v -E 'nologin|false' /etc/passwd | cut -d: -f1

Output:

root
ravi
priya
  1. Check for extra UID 0.
awk -F: '$3==0' /etc/passwd

Output:

root:x:0:0:root:/root:/bin/bash
  1. Who can use sudo?
getent group wheel sudo

Output:

wheel:x:10:ravi,priya
  1. 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.

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

  1. 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.
  2. Use awk on /etc/passwd to print every user whose shell is /bin/bash.

Practise this chapter

Interview questions and answers

A shared report remains unreadable after you add a user to a group. What would you inspect?

I would compare group membership in a fresh process with the file’s numeric group and permission bits, including the containing directories. A long-running process may still have old memberships. On shared storage, matching group names do not prove the numerical IDs are aligned.

Check your understanding

Choose an answer, then compare your reasoning with the explanation.

0 of 3 answered correctly
1. What does plain id show for a login shell?

Answer and explanation

B. The process’s effective user and group information

Without a username argument, id reports information about the current process identity.

2. A user was added to an extra group, but the old shell cannot use it. What should you try first?

Answer and explanation

C. Start a fresh login and check id again

An existing login may retain its old supplementary group set until it starts a new session.

3. When comparing shared file group ownership across Linux systems, what matters to ordinary permission checks?

Answer and explanation

A. The numeric GID in the actual credential and file metadata

Linux matches numeric identities. The visible group name is a local label for that number.

Practice Tasks

Practice checks run in your browser. They check the answer for this exercise; they do not create resources or connect to your AWS account.

About this scenario

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

Check before running admin work.

Emily Tremblay at Maple Leaf Books wants to print only the name of user kavya's primary group.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy UID and groups

Access problems start with groups.

Show the UID, GID and groups of user kavya.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Only group names

Quick check of membership.

List only the group names of user deploy.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Create a user with home

New joiner at BIZ.

Create user nikhil with a home folder.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Set a password

A new user needs a password.

Set the password of user nikhil (as root).

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Create a group

Teams share files through groups.

Create a group named finance.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Easy Recent logins

Who logged in after the incident?

Show the last 5 logins.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Look up a user entry

Works for local and LDAP users.

Print the passwd entry for user ravi using the name service lookup tool.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium User with shell and groups

Developers need bash and the devs group.

Create user asha with a home, bash as shell and extra group devs.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium System user for a service

Services must not log in.

Create a system user named appsvc with no login shell (/sbin/nologin).

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Force change at next login

Temporary passwords must be changed.

Expire the password of nikhil so he must change it at next login.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Add to a group safely

Without -a, other groups are removed.

Add user priya to the docker group without removing her other groups.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Lock an account

Someone is on long leave.

Lock the account of user rahul with usermod.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Remove a user and home

Leaver cleanup.

Delete user intern1 together with the home folder.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium See password ageing

Audits ask for expiry.

List the password ageing details of user kavya.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Medium Become a user with login shell

Test what deploy sees.

Switch to user deploy with a full login environment using su.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

Hard Max password age 90 days

Policy at BIZ says 90 days.

Set the maximum password age of priya to 90 days.

  1. Find the Linux command that does this job.
  2. Add the options (like -r or -h) the task needs.
  3. Add the file names, folders or users in the right order.
  4. Use sudo if the job changes system files or users. Click Check answer.

In short

  1. whoami, id and groups show who you are.
  2. /etc/passwd 7 fields; hashes in /etc/shadow; groups in /etc/group.
  3. useradd -m -s -G -r -e creates users.
  4. usermod -aG adds a group; never plain -G.
  5. passwd -l, usermod -L -e 1 and userdel -r offboard users.
  6. 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.

Add a user right. Every person gets their own login. useradd -m makes the home folder. Set a password, force change. Create with bash and groups.
Revision card: Add a user right · Download PNG · Open card page
Groups in 4 steps. Share access by team, not person. groupadd creates, id checks. Always -aG, never -G alone. Add to docker group.
Revision card: Groups in 4 steps · Download PNG · Open card page
useradd vs adduser. Low-level, same on all distros. / Friendly script on Debian.
Comparison: useradd vs adduser · Download PNG · Open card page
usermod -G vs usermod -aG. Replaces all extra groups. / Adds to the existing groups.
Comparison: usermod -G vs usermod -aG · Download PNG · Open card page
passwd vs shadow?. passwd lists users, world readable. shadow holds hashes, root only. Look up a user.
Interview card: passwd vs shadow? · Download PNG · Open card page
Why -aG, not -G?. -G alone replaces all groups. -a appends to the list. Safe add.
Interview card: Why -aG, not -G? · Download PNG · Open card page
Added to group, still denied?. Groups load at login. Log out and in, or newgrp. Check current groups.
Interview card: Added to group, still denied? · Download PNG · Open card page
System user for a service?. No login, no home needed. Low UID, nologin shell. Create it.
Interview card: System user for a service? · Download PNG · Open card page

More cards: Ravi Sir's Cards.