Linux › Section G · System configuration › Topic G.3
User management files
A Linux account is nothing more than a few lines in a few text files. Once you can read those lines field by field and know which commands edit them safely, creating, locking and ageing accounts becomes routine rather than mysterious.
Accounts live in plain text files
Four files describe the users and groups of a classic Linux system. /etc/passwd lists accounts and is readable by everyone, because programs constantly need to turn a number into a name. /etc/shadow holds password hashes and ageing data and is readable only by privileged users. /etc/group lists groups and their members, and /etc/gshadow is its protected companion. Every file uses one record per line with fields separated by colons. On systems that use a directory service such as LDAP, accounts can also come from elsewhere, as the topic on user IDs and user access explains, but the local files remain the foundation.
The seven fields of /etc/passwd
A passwd line has seven fields in this order: login name, password placeholder, UID, primary GID, comment (the full name, historically called GECOS), home directory, login shell. For example, ana:x:1001:1050:Ana Ruiz:/home/ana:/bin/bash. The x means the hash is in /etc/shadow. UID 0 is root. System accounts for daemons usually have UIDs below 1000, and ordinary users start at UID_MIN, which is 1000 by default in /etc/login.defs. Accounts that must never log in interactively get a shell such as /usr/sbin/nologin or /bin/false. An empty shell field means /bin/sh is used.
Groups and /etc/group
A group line has four fields: group name, password placeholder, GID and a comma-separated list of members, as in projx:x:1050:sam,ana. Each user has exactly one primary group, the GID in field four of passwd, and any number of supplementary groups, which are the group lines that list the user as a member. New files take the user's primary group by default, while supplementary groups grant extra access. Many distributions create a private group with the same name as each user. Administrative groups differ by family: Debian and Ubuntu use sudo, while Fedora and RHEL use wheel.
The nine fields of /etc/shadow
A shadow line has nine fields: 1 login name; 2 hashed password; 3 date of last change; 4 minimum age; 5 maximum age; 6 warning period; 7 inactivity period; 8 account expiry date; 9 reserved. Dates are counted in days since 1 January 1970, and the ages are in days. The hash starts with an algorithm marker such as $6$ for SHA-512 or $y$ for yescrypt. A leading ! in field 2 means the password is locked, and a lone ! or * means no password can ever match. An empty field 8 means the account never expires. Password expiry and account expiry differ: an expired password can still be replaced at login, but an expired account is blocked completely.
Worked example: decoding a shadow line
Read this line, with the hash shortened to HASH: ana:HASH:20697:1:90:7:14::. 1. Field 3 is 20697 days after 1 January 1970, which python confirms is 1 September 2026. 2. Field 4 is 1, so Ana must wait a day between changes. 3. Field 5 is 90, so the password expires 90 days later, on 30 November 2026 (day 20787). 4. Field 6 is 7, so warnings begin seven days before, on 23 November 2026. 5. Field 7 is 14, so the password still works for 14 days after expiry, until 14 December 2026, when the account locks. 6. Field 8 is empty, so the account never expires outright. Check: 20697 + 90 = 20787, and 20787 - 7 = 20780, which is 23 November.
Creating and changing accounts
useradd -m -s /bin/bash -c 'Ana Ruiz' -G sudo ana creates a user: -m creates the home directory, -s sets the shell, -c the comment and -G the supplementary groups (comma-separated, no spaces). Without -m a home directory is created only if CREATE_HOME is set in /etc/login.defs. -r makes a system account. passwd ana sets a password; passwd -l and passwd -u lock and unlock it; passwd -e forces a change at next login. usermod changes accounts: usermod -aG projx ana appends a group, usermod -s sets the shell, and -L and -U lock and unlock. userdel ana removes the account, and -r also deletes the home directory. groupadd and groupdel manage groups. Debian-family systems also offer adduser, a friendlier wrapper.
The skeleton directory
When useradd -m creates a home directory, it copies the contents of /etc/skel into it, commonly files such as .bashrc and .profile. This gives every new user the same starting dot files. The copy happens once, at creation: adding a file to /etc/skel today does not change existing users, though it will appear in every home directory created afterwards. The directory can be overridden with -k. Defaults for new accounts, including the shell and the base for home directories, come from /etc/default/useradd, while password policy defaults and the UID ranges live in /etc/login.defs.
Password ageing with chage
chage manages the fields of shadow without editing the file. chage -l ana lists the ageing information, and ordinary users may run it on themselves. -M sets the maximum age, -m the minimum, -W the warning days, -I the inactivity days, -E the account expiry date and -d the date of last change; chage -d 0 ana forces a new password at the next login. Dates may be written as YYYY-MM-DD. Passing -1 to -M, -I or -E removes that limit. Setting an ageing policy for a new user at the same time as creation is good practice, because the defaults in login.defs often allow passwords that never expire.
Worked example: a contractor with an end date
Sam will work on project X until 30 March 2027. 1. Create the group: sudo groupadd projx. 2. Create the account: sudo useradd -m -s /bin/bash -c 'Sam Lee' -G projx -e 2027-03-31 sam. 3. Set a temporary password with sudo passwd sam, then force a change at first login: sudo passwd -e sam. 4. Set ageing: sudo chage -M 90 -W 7 sam. 5. Verify: id sam shows the groups, getent passwd sam shows the record, and chage -l sam lists the dates. 6. Check the arithmetic: field 8 of Sam's shadow line now holds 20908, the number of days from 1 January 1970 to 31 March 2027. The account is expired from the start of that day, so from 31 March Sam cannot log in at all.
Common mistakes to avoid
First, running usermod -G projx sam without -a, which replaces all supplementary groups and silently removes the user from the rest. Second, expecting a group change to affect a session already open; it applies at the next login. Third, editing /etc/passwd or /etc/shadow with an ordinary editor; vipw and vipw -s lock the file while you edit, pwck checks it afterwards, and a syntax error can lock everyone out. Fourth, confusing password expiry (chage -M) with account expiry (chage -E). Fifth, treating a leading ! as an empty password when it means locked. Sixth, forgetting that userdel without -r leaves the home directory behind.
Key takeaways
passwd has seven fields (name, x, UID, GID, comment, home, shell); group has four; shadow has nine, with dates in days since 1970. UIDs below 1000 are normally system accounts. useradd -m creates a home from /etc/skel once; usermod -aG appends groups; passwd -l locks; userdel -r removes the home. chage -l shows ageing and -M, -m, -W, -I, -E, -d set it. Password expiry and account expiry are different fields. Prefer the commands, or vipw, over raw editing.
Flashcards
Flashcard
Account list: name, x, UID, GID, comment, home, shell
Test your understanding
Question 1 of 5
In the passwd line ana:x:1001:1050:Ana Ruiz:/home/ana:/bin/bash, what is Ana's primary group ID?
Question 2 of 5
A shadow entry has last change 20697 (1 September 2026), maximum age 90 and warning period 7. On which date do warnings begin?
Question 3 of 5
Sam already belongs to the groups docker and audio. Which command adds him to projx while keeping those memberships?
Question 4 of 5
You want a contractor's account to stop working completely on 31 March 2027, whatever the state of the password. Which setting does this?
Question 5 of 5
On Monday an administrator adds a file to /etc/skel. Who receives it?
