
Manage Users on Linux -Learn how to add, modify, and remove users on Linux. This guide covers both Ubuntu/Debian (apt family) and CentOS/AlmaLinux (dnf family) distributions.
Before starting make sure ur linux is ready.
- Ubuntu: ubuntu.com/download
- Debian: debian.org/distrib
- CentOS Stream: centos.org/download
- AlmaLinux: almalinux.org/download
- Talkecho full toturial: Click here
Why Manage Users on Linux Matters
Linux is a multi-user system. Even if you’re the only one using your machine, proper user management ensures security, permissions control, and system stability. Each user gets their own home directory, shell, and permissions.
Adding a New User
On Ubuntu/Debian:
sudo adduser alex
This creates the user alex
, assigns a home directory (/home/alex
), and prompts you to set a password.
On CentOS/AlmaLinux:
sudo adduser alex
sudo passwd alex
The second command sets the user’s password.
Granting Sudo (Admin) Privileges
To allow a user to run administrative commands:
sudo usermod -aG sudo alex # Ubuntu/Debian
sudo usermod -aG wheel alex # CentOS/AlmaLinux
The -aG
flag appends the user to a group (sudo
or wheel
depending on distro).
Switching Between Users
# switch to another user
su - alex
# return to your account
exit
You can also log in as a user via SSH:
ssh alex@server-ip
Changing User Settings
Modify user properties with usermod
:
# change username
sudo usermod -l newname oldname
# change home directory
sudo usermod -d /home/newdir -m alex
# change default shell
sudo usermod -s /bin/bash alex
Deleting Users
To remove a user:
sudo deluser alex # Ubuntu/Debian
sudo userdel alex # CentOS/AlmaLinux
To delete the user and their home directory:
sudo deluser --remove-home alex # Ubuntu/Debian
sudo userdel -r alex # CentOS/AlmaLinux
Viewing Users & Groups
# list all users
cut -d: -f1 /etc/passwd
# list all groups
cut -d: -f1 /etc/group
# show groups for a specific user
groups alex