Essential Linux Commands for Managing Users and Groups

shilpa tangashilpa tanga
2 min read

Table of contents

User Management

  1. useradd → Creates new user account in system.

    useradd john

  2. passwd → Sets/update a user’s password

    passwd john

  3. usermod → modifies a user’s account properties such as username, home directory or shell

    usermod -l newname john

  4. userdel → Deletes a user account from the system

    userdel john

  5. chage → Manages password expiration settings for a user

    chage -l john (to list password expiration details)

  6. su → switches the current user session to another user account(like root)

    su - john

  7. whoami → Displays the username of current user

    whoami

  8. id → Shows the user ID(UID) and group ID(GID) of a user

    id john

  9. finger → Displays detailed information about a user, such as login time and home directory

    finger john

Group Management

  1. groupadd → Creates a new group in the system.

    groupadd devops

  2. groupdel → Deletes an existing group from the system.

    groupdel devops

  3. groupmod → Modifies name or GID of a group

    groupmod -n newgroup devops

  4. gpasswd → Administers a group by adding or removing members

    gpasswd -a john devops (adds user to group)

User and Group Administration

  1. usermod -aG → adds a user to a supplementary group

    usermod -aG sudo john

  2. groups → Displays the groups that a user belongs to.

    groups john

  3. newgrp → login to a new group , changing the user’s group ID during session.

    newgrp devops

  4. chown → Changes the ownership of the file or directory to a users or group

    chown john:devops file.txt

  5. chmod → Modifies the permissions of a file or directory for users, groups and others

    chmod 755 file.txt

  6. getent →Retrieves entries from the system’s user, group or other administrative database

    getent passwd john(fetches user info)

  7. last → Displays a list of the last logged on users

    last

  8. w → Shows who is logged in and what they are doing.

    w

  9. 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.

0
Subscribe to my newsletter

Read articles from shilpa tanga directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

shilpa tanga
shilpa tanga