Command | Purpose | Key Options | Example |
---|---|---|---|
useradd | Add a new user to the system | -m (create home dir), -G group (assign to group), -s shell (set default shell) | sudo useradd -m -G developers -s /bin/bash john |
usermod | Modify an existing user account | -aG group (add to group), -s shell (change shell), -l login (change username) | sudo usermod -aG sudo john |
passwd | Change a user’s password | --stdin (provide password through stdin) | sudo passwd john |
userdel | Delete a user account | -r (remove home directory) | sudo userdel -r john |
chage | Set or display password aging for a user | -l (list info), -M days (maximum days between password changes) | sudo chage -M 90 john |
who | Show who is logged into the system | None | who |
w | Show who is logged in and what they are doing | None | w |
id | Display user ID, group ID, and other group memberships | None | id john |
groups | Show the groups a user belongs to | None | groups john |
finger | Display information about a user | None | finger john |
su | Switch to another user | - (start login shell), -c command (run command as another user) | su - john or su -c "whoami" |
sudo | Execute a command as another user or as root | -u user (run as another user), -i (run as login shell) | sudo -u john -i or sudo ls /root |
last | Show listing of last logged-in users | None | last john |
lastlog | Report the most recent login of all users | -u user (check specific user) | lastlog -u john |
whoami | Display the current logged-in user’s username | None | whoami |
adduser | Add a user (alternative to useradd , simpler UI) | None | sudo adduser john |
deluser | Delete a user (alternative to userdel ) | None | sudo deluser john |
Managing User Accounts
User Management Commands in Linux
You don’t have access to this lesson
Please register or sign in to access the course content.