Script Valley
Linux Basics Complete Course: From Beginner to System Administrator
Module 4: Permissions, Users, and GroupsLesson 4.2

Managing Linux Users and Groups | useradd usermod passwd

useradd, usermod, userdel, groupadd, passwd, sudo, /etc/passwd, /etc/shadow

Managing Linux Users and Groups

Linux is a multi-user operating system, and user and group management is a critical system administration task. Every process runs as a specific user, and permissions are enforced based on user identity and group membership. Understanding how to add, modify, and remove users and groups is fundamental to Linux basics.

User Account Files

Linux stores user information in /etc/passwd, which contains one line per user with fields for username, password placeholder, user ID (UID), group ID (GID), comment, home directory, and shell. Encrypted passwords are stored separately in /etc/shadow, which is readable only by root.

cat /etc/passwd | grep alice
cat /etc/shadow | grep alice
id alice

Creating Users with useradd

The useradd command creates a new user account. The -m flag creates the user's home directory, -s sets the login shell, -G adds the user to supplementary groups, and -c adds a comment (usually the user's full name).

sudo useradd -m -s /bin/bash -c "Alice Smith" alice
sudo useradd -m -G sudo,developers -s /bin/bash bob
sudo passwd alice

After creating a user, set their password with the passwd command. Without -m, the home directory is not created automatically on some distributions.

Modifying Users with usermod

The usermod command modifies an existing user account. Use -aG to append the user to a group without removing them from other groups. Omitting the -a flag would replace all group memberships.

sudo usermod -aG sudo alice
sudo usermod -aG docker alice
sudo usermod -s /bin/zsh alice
sudo usermod -l newname oldname

Deleting Users

The userdel command removes a user. The -r flag also removes the user's home directory and mail spool.

sudo userdel alice
sudo userdel -r bob

Managing Groups

The groupadd command creates new groups. The gpasswd command manages group membership. The groups command shows which groups a user belongs to.

sudo groupadd developers
sudo gpasswd -a alice developers
groups alice
cat /etc/group | grep developers

sudo and the sudoers File

The sudo command allows permitted users to run commands as root. Users in the sudo group (on Ubuntu/Debian) or wheel group (on CentOS) can use sudo. The sudoers configuration is at /etc/sudoers and should be edited with visudo to prevent syntax errors.

sudo apt update
sudo visudo
Managing Linux Users and Groups | useradd usermod passwd — Module 4: Permissions, Users, and Groups — Linux Basics Complete Course: From Beginner to System Administrator — Script Valley — Script Valley