Home Blog Certs Knowledge Base About

LPIC-1 107.1 โ€” Manage User and Group Accounts

Exam weight: 5 โ€” LPIC-1 v5, Exam 102

What You Need to Know

From the official LPIC-1 objectives:

  • Add, modify, and remove users and groups.
  • Manage user/group info in password and group databases.
  • Create and manage special-purpose and limited accounts.

Key files and commands: /etc/passwd, /etc/shadow, /etc/group, /etc/gshadow, /etc/skel, /etc/login.defs, useradd, usermod, userdel, groupadd, groupmod, groupdel, passwd, chage, getent.


User Account Files

/etc/passwd

Every local user has one line in /etc/passwd with seven colon-separated fields:

frank:x:1001:1001:Frank User:/home/frank:/bin/bash
FieldExampleDescription
UsernamefrankLogin name
Passwordxx means the password is stored in /etc/shadow
UID1001User ID number
GID1001Primary group ID
GECOSFrank UserFull name / comment
Home Directory/home/frankUser’s home directory
Shell/bin/bashDefault login shell

System accounts typically have UIDs below 1000; ordinary user accounts use UIDs of 1000 and above.

/etc/shadow

Stores password hashes and aging information (readable by root only):

frank:$6$...:18600:0:99999:7:::
FieldDescription
UsernameLogin name
Encrypted PasswordHash; ! prefix means account is locked
Last ChangeDays since 1970-01-01 when password was last changed; 0 = must change at next login
Minimum AgeMinimum days before password can be changed
Maximum AgeMaximum days before password must be changed
Warning PeriodDays before expiry that user is warned
Inactivity PeriodDays after expiry before account is disabled
Expiration DateDays since 1970-01-01 when account expires; empty = never
ReservedUnused

/etc/group

Each group occupies one line with four fields:

db-admin:x:1050:frank,emma
FieldDescription
Group NameName of the group
Group Passwordx means password stored in /etc/gshadow
GIDGroup ID number
Member ListComma-separated list of secondary members (primary members are not listed)

/etc/gshadow

Group shadow file with four fields: group name, encrypted password (! = no newgrp access), group administrators, group members.


Managing Users

useradd

Creates a new user account. Common options:

OptionDescription
-c commentGECOS field (full name, etc.)
-d dirHome directory path
-e YYYY-MM-DDAccount expiry date
-f daysDays after password expiry before account is disabled
-g GIDPrimary group (name or GID)
-G group,...Additional (secondary) groups
-k dirSkeleton directory (requires -m)
-mCreate home directory
-MDo not create home directory
-s shellLogin shell
-u UIDSpecify UID

Example โ€” create user emma with home directory and bash shell:

useradd -m -s /bin/bash -c "Emma User" emma

usermod

Modifies an existing user account. Options mirror useradd with additions:

OptionDescription
-d dir [-m]Change home directory; -m also moves existing contents
-G groups [-a]Set secondary groups; -a appends instead of replacing
-l newnameRename login name
-LLock account (prepends ! to password hash in shadow)
-UUnlock account (removes !)

userdel

Removes a user account. Use -r to also delete the home directory and mail spool:

userdel -r emma

Managing Groups

CommandDescription
groupadd -g GID nameCreate a new group with optional GID
groupmod -n newname nameRename a group
groupmod -g GID nameChange a group’s GID
groupdel nameDelete a group

Password and Aging โ€” passwd and chage

passwd

Manages user passwords and account locking:

OptionDescription
-dDelete password (no password required)
-eForce password change on next login
-i daysInactivity period after expiry
-lLock account
-n daysMinimum password lifetime
-SShow account status
-uUnlock account
-w daysWarning days before expiry
-x daysMaximum password lifetime

chage

Manages password expiry and aging:

OptionDescription
-d YYYY-MM-DDSet date of last password change
-E YYYY-MM-DDSet account expiry date
-I daysSet inactivity period
-lList account aging info (non-root can run for own account)
-m daysMinimum password age
-M daysMaximum password age
-W daysWarning days before expiry

passwd โ†” chage equivalents

passwdchageMeaning
-n-mMinimum password lifetime
-x-MMaximum password lifetime
-w-WWarning days
-i-IInactivity days
-S-lShow status/list

To lock an account: usermod -L username or passwd -l username.
To unlock an account: usermod -U username or passwd -u username.


Skeleton and Login Defaults

/etc/skel

When useradd -m creates a home directory, the contents of /etc/skel are copied into it. Place default config files (.bashrc, .profile, etc.) here.

/etc/login.defs

System-wide defaults for user/group creation:

DirectiveMeaning
UID_MIN / UID_MAXUID range for ordinary users
GID_MIN / GID_MAXGID range for ordinary groups
CREATE_HOMEWhether to create home by default
USERGROUPS_ENABCreate a matching group for each new user
MAIL_DIRMail spool directory
PASS_MAX_DAYSDefault maximum password age
PASS_MIN_DAYSDefault minimum password age
PASS_MIN_LENMinimum password length
PASS_WARN_AGEDefault warning days

Querying Accounts โ€” getent

getent retrieves entries from Name Service Switch (NSS) databases, supporting both local files and network directories (LDAP, NIS):

getent passwd emma
# emma:x:1020:1020:User Emma:/home/emma:/bin/bash

getent group db-admin
# db-admin:x:1050:frank,emma

Quick Reference

User account files:
  /etc/passwd      7 fields: username:x:UID:GID:GECOS:home:shell
  /etc/shadow      9 fields: username:hash:lastchg:min:max:warn:inactive:expire:reserved
  /etc/group       4 fields: groupname:x:GID:members
  /etc/gshadow     4 fields: groupname:hash:admins:members

Creating users:
  useradd -m -s /bin/bash -c "Name" -G group1,group2 username
  useradd flags: -c -d -e -f -g -G -k -m -M -s -u

Modifying users:
  usermod -d -m   move home directory
  usermod -G -a   append secondary groups
  usermod -l      rename login
  usermod -L/-U   lock / unlock

Deleting users:
  userdel -r username    remove user + home + mail spool

Groups:
  groupadd -g GID name
  groupmod -n newname -g GID name
  groupdel name

Passwords & aging:
  passwd -l/-u    lock / unlock
  passwd -x/-n/-w/-i   max/min/warn/inactive days
  chage -M/-m/-W/-I    same via chage
  chage -E YYYY-MM-DD  set account expiry
  chage -l username    list aging info

Skeleton & defaults:
  /etc/skel        copied to new home directories
  /etc/login.defs  system defaults for UIDs, GIDs, password aging

Query NSS databases:
  getent passwd username
  getent group groupname

Exam Questions

  1. What command creates user frank with a home directory and bash shell? โ†’ useradd -m -s /bin/bash frank
  2. What does usermod -L username do? โ†’ Locks the account by prepending ! to the password hash in /etc/shadow.
  3. What is the equivalent of passwd -l? โ†’ usermod -L โ€” both lock the account.
  4. How do you append a user to secondary group staff without removing existing groups? โ†’ usermod -aG staff username
  5. What command changes the maximum password age to 90 days? โ†’ chage -M 90 username or passwd -x 90 username
  6. What file stores password hashes on Linux? โ†’ /etc/shadow
  7. What does a ! prefix in the password field of /etc/shadow mean? โ†’ The account is locked.
  8. What is /etc/skel? โ†’ Directory whose contents are copied to a new user’s home directory when it is created.
  9. What command removes user emma and her home directory? โ†’ userdel -r emma
  10. What does getent passwd emma do? โ†’ Queries the NSS passwd database for user emma โ€” works with local files and network directories.
  11. How many fields does /etc/passwd have? โ†’ 7: username, password placeholder, UID, GID, GECOS, home, shell.
  12. How many fields does /etc/shadow have? โ†’ 9: username, hash, last-change, min, max, warn, inactive, expire, reserved.
  13. What UID range is typically used for ordinary users? โ†’ 1000 and above (system accounts are below 1000).
  14. What file defines system-wide defaults for user creation such as UID_MIN? โ†’ /etc/login.defs
  15. What command lists aging information for a user account? โ†’ chage -l username
  16. Which option of chage sets the account expiry date? โ†’ -E YYYY-MM-DD
  17. What does userdel do without the -r flag? โ†’ Removes the user account but leaves the home directory and mail spool intact.
  18. How do you force a user to change their password on next login? โ†’ passwd -e username or chage -d 0 username

Exercises

Exercise 1 โ€” Create a Developer Account

Create user dev1 with UID 2001, home directory /home/dev1, bash shell, and secondary group developers. What command achieves this?

Answer
useradd -u 2001 -m -s /bin/bash -G developers dev1

This creates the user with the specified UID (-u 2001), creates a home directory (-m), sets the shell (-s), and assigns the secondary group (-G developers).


Exercise 2 โ€” Lock and Unlock an Account

A user account must be temporarily disabled while an employee is on leave. What are two ways to lock it, and how do you unlock it?

Answer

Lock:

  • usermod -L username โ€” prepends ! to password hash
  • passwd -l username โ€” same effect

Unlock:

  • usermod -U username
  • passwd -u username

Both methods modify the password field in /etc/shadow.


Exercise 3 โ€” Password Aging Policy

Set a password policy for user frank where: maximum age is 60 days, minimum age is 2 days, warning 7 days before expiry, and inactivity lock after 14 days.

Answer
chage -M 60 -m 2 -W 7 -I 14 frank

Equivalently with passwd:

passwd -x 60 -n 2 -w 7 -i 14 frank

Exercise 4 โ€” Reading /etc/shadow

Given this shadow entry: emma:$6$abc:19000:5:90:7:30:19365:

Interpret each field.

Answer
FieldValueMeaning
UsernameemmaLogin name
Password$6$abcSHA-512 hash
Last change19000Day 19000 since 1970-01-01
Min age5Can’t change for 5 days
Max age90Must change every 90 days
Warning7Warned 7 days before expiry
Inactivity30Locked 30 days after expiry
Expiration19365Account expires on day 19365 since epoch
Reserved(empty)Unused

Exercise 5 โ€” Group Membership

User kevin needs to be added to the sysadmin group as a secondary group without losing existing group memberships. What command achieves this?

Answer
usermod -aG sysadmin kevin

The -a flag is critical โ€” without it, -G would replace all current secondary group memberships with only sysadmin.


LPIC-1 Study Notes | Topic 107: Administrative Tasks