Linucate
~ Linucate_

107.1 Manage User and Group Accounts

All Levels

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 getent to 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:

  • -aG appends supplementary groups
  • forgetting -a can accidentally replace group membership instead of extending it

Remove Users

sudo userdel alice
sudo userdel -r alice

Simple idea:

  • userdel removes the account
  • userdel -r also 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:

  1. inspect the current state with getent
  2. create or modify the account
  3. set password or group membership as needed
  4. check the result again

Practice Step by Step

1) Create a user and set a password
  1. Run: sudo useradd -m alice
  2. Set a password: sudo passwd alice
  3. Check: getent passwd alice
2) Add a user to a supplementary group
  1. Create a group: sudo groupadd devs
  2. Add the user to it: sudo usermod -aG devs alice
  3. Verify: id alice
3) Inspect password aging information
  1. Run: sudo chage -l alice
  2. 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 homes
  • useradd = create user
  • usermod = modify user
  • userdel = remove user
  • groupadd, groupmod, groupdel = manage groups
  • passwd = set password
  • chage = manage password aging
  • getent = query account databases safely
🎯

Test Your Knowledge

Complete the quiz to assess your understanding of this course's concepts.