User Management in Linux

In Linux there are 3 user type:
Root user → Root user id is 0.
System user → System user has ids from 1 to 999.
Local user → Local user has ids greater than 999.
Why we don’t use root user for everyday task ?
If there are two users, John and Jane, both of whom can use the root account, and one of them uses rm -rf
, it would be difficult to determine who is responsible. Therefore, we should create separate accounts with the same sudo privileges so that we can track user activity through logs.
Commands
whoami → username of the system
sudo cat /etc/passwd → List the user in the system
root:x:0:0:root:/root:/bin/bash
root→username
x→ password placeholder
0→User ID (UID)
0→Group ID (GID)
root → User description (GECOS)
/root → Home directory
/bin/bash → Login shell (default shell)
sudo cat /etc/shadow → To get the user password
To create users we have two different method
Low level Command
sudo useradd amit
sudo passwd amit
We don’t create users at a low level because we also have to create groups and set other permissions.
High Level Command
sudo adduser amit
sudo cat /etc/group → To get the group information
To add user in a group:
sudo usermod -aG groupname username
Remove group
sudo delgroup groupname
To change the name of user
sudo usermod -l newname oldname
What is sudo ?
sudo
is a group. sudo
stands for "superuser do." Most system-level operations (like installing software, modifying system files, or restarting services) require elevated privileges. sudo
allows you to perform these operations without logging in as the root user, which is safer.
Key Benefits:
Security: Avoids using the root account directly.
Auditability: Logs all
sudo
usage.Control: Admins can fine-tune what commands a user can run via
sudo
.
Subscribe to my newsletter
Read articles from Amit Jajoo directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
