Essential Linux Commands for Managing Users and Groups
Table of contents
User Management
useradd → Creates new user account in system.
useradd john
passwd → Sets/update a user’s password
passwd john
usermod → modifies a user’s account properties such as username, home directory or shell
usermod -l newname john
userdel → Deletes a user account from the system
userdel john
chage → Manages password expiration settings for a user
chage -l john
(to list password expiration details)su → switches the current user session to another user account(like root)
su - john
whoami → Displays the username of current user
whoami
id → Shows the user ID(UID) and group ID(GID) of a user
id john
finger → Displays detailed information about a user, such as login time and home directory
finger john
Group Management
groupadd → Creates a new group in the system.
groupadd devops
groupdel → Deletes an existing group from the system.
groupdel devops
groupmod → Modifies name or GID of a group
groupmod -n newgroup devops
gpasswd → Administers a group by adding or removing members
gpasswd -a john devops
(adds user to group)
User and Group Administration
usermod -aG → adds a user to a supplementary group
usermod -aG sudo john
groups → Displays the groups that a user belongs to.
groups john
newgrp → login to a new group , changing the user’s group ID during session.
newgrp devops
chown → Changes the ownership of the file or directory to a users or group
chown john:devops file.txt
chmod → Modifies the permissions of a file or directory for users, groups and others
chmod 755 file.txt
getent →Retrieves entries from the system’s user, group or other administrative database
getent passwd john
(fetches user info)last → Displays a list of the last logged on users
last
w → Shows who is logged in and what they are doing.
w
who → Displays the list of currently logged-in users
who
These commands are foundational for managing users and groups in Linux systems, helping with tasks from creating accounts to handling permissions.
Subscribe to my newsletter
Read articles from shilpa tanga directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by