User and group accounts
Accounts and groups: the four files that hold them, the commands that edit those files safely, and what actually happens to a home directory when an account is created or removed.
Lesson 1 of 3 in objective 107. Administrative tasks, part of LPIC-1 Exam 102-500.
Four files, and which one holds the password
/etc/passwd has one line per account with seven colon-separated fields: name, an x standing in for the password, UID, GID, the comment or GECOS field, home directory, and login shell. It is world-readable, which is exactly why the password is not in it. /etc/shadow holds the hashed password and the ageing fields — last change, minimum and maximum age, warning period, inactivity, expiry — and is readable only by root.
/etc/group lists groups with their GIDs and their supplementary members, and /etc/gshadow holds group passwords and administrators. A user's PRIMARY group is the GID in their passwd line and is not listed in /etc/group as a member; supplementary groups are. id prints both, groups prints the names, and getent looks an entry up through whatever name service is configured rather than only in the local file — which matters the moment LDAP is involved.
The commands, and what they do to the filesystem
useradd creates an account, with -m to create the home directory (copied from /etc/skel), -s for the shell and -G for supplementary groups; adduser on Debian systems is an interactive wrapper over it. usermod changes an existing account — and the trap is that usermod -G REPLACES the supplementary group list, so adding a group means usermod -aG, with the -a for append. userdel removes the account and userdel -r also removes the home directory and mail spool.
groupadd, groupmod and groupdel do the same for groups. passwd sets a password; passwd -l locks an account by prefixing the hash with a character that can never match, and passwd -u unlocks it. chage manages the ageing fields — chage -l lists them — and setting a shell of /sbin/nologin or /bin/false is the other way to stop an account being used interactively while leaving it functional for a service.
gpasswd is the one that maintains /etc/gshadow, and it is how group membership is delegated without handing out root or writing a sudo rule: gpasswd -A alice developers makes alice an ADMINISTRATOR of that group, recorded in /etc/gshadow, after which she may add and remove members herself. Its other flags act on the membership rather than the delegation — -a adds one member and -d removes one, -M replaces the member list outright, and gpasswd with only a group name sets the group password that newgrp asks for. /etc/gshadow is to /etc/group what /etc/shadow is to /etc/passwd: the root-only companion file.
The two fields a user might reasonably want to change themselves have their own commands. chfn -f "Alice Okafor" alice writes the fifth field of the /etc/passwd line — the GECOS or comment field, conventionally full name, room, work phone and home phone, and where a mail client picks up a display name — and chsh -s /bin/bash alice writes the seventh, the login shell. Both are setuid so that a user may correct their own entry. usermod does the same two jobs from the administrator's side with -c and -s, replacing the whole field rather than editing named parts of it, so usermod -c and chfn -f are two correct answers to the same question.
A UID of 0 means root, whatever the account is called; there is nothing else special about the name. System accounts conventionally take low UIDs, with the boundary set in /etc/login.defs.
Worth carrying in
- /etc/passwd
- name:x:UID:GID:comment:home:shell. World-readable; no password in it.
- /etc/shadow
- Hashed passwords and ageing. Root-only.
- useradd -m -s /bin/bash
- Create an account with a home directory from
/etc/skel. - usermod -aG group user
- ADD a supplementary group. Without -a, the list is replaced.
- userdel -r
- Delete the account AND its home directory and mail spool.
- passwd -l / -u
- Lock and unlock an account.
- chage -l user
- Password ageing settings for an account.
- getent passwd user
- Look up through the name service, not just the local file.
- id / groups
- UID, primary GID and supplementary groups for a user.
- gpasswd -A user group
- Delegate group administration. Written to
/etc/gshadow; -a and -d add and remove members. - chfn -f "Name" user
- Set the GECOS field.
chsh -ssets the shell;usermod-c and -s do both as root.
What the exam does with this
usermod-G replaces the group list;usermod-aG appends. This is the most-tested trap on the objective.- The password hash is in
/etc/shadow, never in/etc/passwd. userdelalone leaves the home directory behind. -r is what removes it.
- Objective
- 107. Administrative tasks
- Share of the exam
- 20% (the whole objective)
- Questions in this lesson
- 25
- Signed for by a person
- 0
Partly checked. None of the 25 questions here has been read against the cited source by a person. 25 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.
Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.
How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.
Drill this lesson
A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.
Practise User and group accounts
Questions in this lesson
- The account alice already belongs to the supplementary groups audio and video. You must additionally put her in the group developers while keeping her existing memberships. Which command does that? machine-checked
- A departing employee's account bob must be deleted together with his home directory and mail spool. Which command does all of that in one step? machine-checked
- You want every newly created account to start with a company-standard .bashrc already in its home directory. Where do you place that file? machine-checked
- On a host whose accounts come partly from local files and partly from a directory service, `grep alice /etc/passwd` returns nothing even though `id alice` works. Which command shows alice's account entry the way the system itself resolves it? machine-checked
- Policy says passwords must be changed at least every 90 days, and the account carol must comply. Which command sets that maximum password age? machine-checked
- A line in /etc/group reads `developers:x:1500:alice,bob`. What does the final field contain? machine-checked
- Select the THREE statements that correctly describe /etc/shadow on a typical Linux system. machine-checked
- You must lock the password of the account bob so that he cannot authenticate with it, while leaving the account and its files in place. Select the TWO commands that achieve exactly that. machine-checked
- Using usermod, change the login shell of the existing account bob to /bin/zsh. Type the complete command (assume you are already root). machine-checked
- Create a new group named developers with the specific numeric GID 1500. Type the complete command. machine-checked
- As root, display the password aging information (last change, expiry, minimum and maximum age, warning period) for the account alice in readable form. Type the complete command. machine-checked
- You run `useradd dana` on a Debian system and the account appears in /etc/passwd, but /home/dana does not exist and dana's first login lands in a directory that is not there. Which option to useradd would have created the directory? machine-checked
- Every line in /etc/passwd on a healthy modern system has a lone `x` in its second field. What does that `x` mean? machine-checked
- A daemon you are packaging must run under its own unprivileged account. The account should never be logged into, should not appear in the graphical login list, and should take a UID from the range reserved for system accounts. Which useradd option expresses that intent? machine-checked
- The account `jsmith` must be renamed to `jbrown`, and the home directory must move from /home/jsmith to /home/jbrown with all of its contents. Which single command does both? machine-checked
- A contractor's account `pkumar` must stop working entirely after 31 December 2026, whatever the state of their password at that date. Which command sets that? machine-checked
- `groupdel projectx` fails with a complaint that the group cannot be removed. The group has no supplementary members listed in /etc/group, and you are running the command as root. What is the most likely cause? machine-checked
- The team lead alice should be able to add and remove members of the group `developers` herself, without being granted root and without sudo rules. Which command delegates that, and where is the delegation recorded? machine-checked
- You have just reset the password of the account `erin` to a temporary value and now want her forced to choose a new one the very next time she logs in, while leaving the account otherwise usable. Select the TWO commands that achieve this. machine-checked
- Some of this host's groups come from a directory service, so `grep developers /etc/group` returns nothing even though the group exists. Type the complete command, with its database and its key, that prints the entry for the group `developers` as the system resolves it. machine-checked
- A group was created as `devs` and must now be called `developers`, keeping its existing GID and every member. Type the complete command that renames it (assume you are already root). machine-checked
- Your site standard is that ordinary user accounts start at UID 5000 rather than the distribution's default of 1000, so that the numbering does not clash with a directory service. Which file holds UID_MIN and UID_MAX? machine-checked
- To align a workstation with a central directory you run `usermod -u 5001 frank`, changing frank's UID from 1001. He also owns files in /srv/data and a crontab under /var/spool/cron. What is the state of file ownership afterwards? machine-checked
- Reviewing /etc/passwd you find some service accounts with /usr/sbin/nologin as their shell and others with /bin/false. Both prevent an interactive login. What does nologin do that /bin/false does not? machine-checked
- The GECOS field of the account `alice` currently reads `alice` and should read `Alice Okafor`. Select the TWO commands that write that name into the fifth field of her /etc/passwd line. machine-checked
Practise User and group accounts
The rest of objective 107
- User and group accounts — you are here
- Scheduling jobs to run unattended
- Locales, character encodings and time zones