Introduction
This lesson is about user and group accounts.
The main question is:
How do you create, change, and inspect users and groups on a Linux system without breaking login and permission data?
What you should be able to do after this lesson:
- Add, modify, and remove users and groups.
- Recognize
/etc/passwd,/etc/shadow,/etc/group, and/etc/skel/. - Use
useradd,usermod,userdel,groupadd,groupmod,groupdel. - Change passwords and password aging settings.
- Use
getentto inspect account databases safely.
Big Idea: Linux Identity Lives in Databases, Not Just in One Command
When you create a user, Linux is really updating account databases.
The key files to recognize are:
/etc/passwd
/etc/shadow
/etc/group
At beginner level:
/etc/passwd= account identity information/etc/shadow= protected password and aging information/etc/group= group membership data
Add Users
Create a user:
sudo useradd alice
Create a home directory too:
sudo useradd -m alice
Set a password:
sudo passwd alice
Modify Users
Change account properties:
sudo usermod -aG devs alice
sudo usermod -s /bin/bash alice
Important beginner rule:
-aGappends supplementary groups- forgetting
-acan accidentally replace group membership instead of extending it
Remove Users
sudo userdel alice
sudo userdel -r alice
Simple idea:
userdelremoves the accountuserdel -ralso removes the home directory
Use -r carefully.
Groups
Create a group:
sudo groupadd devs
Modify a group:
sudo groupmod -n developers devs
Delete a group:
sudo groupdel developers
Inspecting Account Data
getent
getent passwd alice
getent group devs
Why getent is useful:
- it reads account data the way the system does
- it is safer than guessing based on one file only
View the files directly
grep '^alice:' /etc/passwd
grep '^devs:' /etc/group
Password Aging with chage
Show aging info:
sudo chage -l alice
Set password aging:
sudo chage -M 90 alice
This matters in real admin work and in LPIC.
/etc/skel/
This directory contains template files copied to a new user's home directory.
Common use:
- default shell config files
- default helper directories
That is why new users often start with files such as .bashrc.
Special Purpose and Limited Accounts
Not every account is a normal human login account.
Examples:
- service accounts
- limited accounts
- accounts with disabled login shells
This is common in real Linux systems.
A Safe Workflow
When changing users or groups:
- inspect the current state with
getent - create or modify the account
- set password or group membership as needed
- check the result again
Practice Step by Step
1) Create a user and set a password
- Run:
sudo useradd -m alice - Set a password:
sudo passwd alice - Check:
getent passwd alice
2) Add a user to a supplementary group
- Create a group:
sudo groupadd devs - Add the user to it:
sudo usermod -aG devs alice - Verify:
id alice
3) Inspect password aging information
- Run:
sudo chage -l alice - Read the output as: aging and expiry information for that user.
Cheat Sheet
/etc/passwd= user account identity data/etc/shadow= password hash and aging data/etc/group= group data/etc/skel/= template files for new user homesuseradd= create userusermod= modify useruserdel= remove usergroupadd,groupmod,groupdel= manage groupspasswd= set passwordchage= manage password aginggetent= query account databases safely
Test Your Knowledge
Complete the quiz to assess your understanding of this course's concepts.
