Linux User and Group Management Commands: useradd, usermod, and groupadd Explained

A guide to Linux user and group management commands - useradd, usermod, userdel, passwd, groupadd, groupmod, groupdel, and id - along with the /etc/passwd and /etc/group file structures.

In Linux systems, the concepts of users and groups are used to manage access permissions to files and processes. For a deeper look at how that access control actually works, see The Complete Guide to Linux Permissions .

User Account Information

User account information is primarily stored in the /etc/passwd file. This file contains basic information for all user accounts on the system, with each line corresponding to one user.

Each line in /etc/passwd consists of 7 fields separated by colons :.

[Username]:[Password]:[User ID (UID)]:[Group ID (GID)]:[Comment]:[Home Directory]:[Login Shell]
  • Password: For security reasons, the actual password hash is not stored here directly. Instead, x is displayed, and the password hash is stored in the /etc/shadow file. The /etc/shadow file is accessible only by the root user in read-only mode.

User Information Editing Commands

  • useradd: Adds a new user account.
    sudo useradd -m -s /bin/bash newuser # Create home directory and set bash as shell
    sudo passwd newuser # Set password
    
  • usermod: Modifies an existing user account.
    sudo usermod -aG sudo newuser # Add newuser to the sudo group
    sudo usermod -l new_name old_name # Change username
    
  • userdel: Deletes a user account.
    sudo userdel -r olduser # Delete including home directory
    
  • passwd: Changes a user’s password.
    passwd # Change your own password
    sudo passwd username # Change another user's password (requires root privileges)
    

Group Account Information

Group account information is primarily stored in the /etc/group file. This file contains basic information for all groups on the system, with each line corresponding to one group.

Each line in /etc/group consists of 4 fields separated by colons :.

[Group Name]:[Password]:[Group ID (GID)]:[Members]
  • Password: Group passwords are rarely used. Typically, x is displayed.
  • Members: A comma-separated list of usernames belonging to the group.

Group Information Editing Commands

  • groupadd: Adds a new group.
    sudo groupadd newgroup
    
  • groupmod: Modifies an existing group.
    sudo groupmod -n new_group_name old_group_name # Change group name
    
  • groupdel: Deletes a group.
    sudo groupdel oldgroup
    
  • id: Checks the groups that the current user belongs to.
    id
    # Example: uid=1000(username) gid=1000(username) groups=1000(username),4(adm),27(sudo)
    

Understanding and properly using these commands enables effective user and group management in Linux systems.

FAQ

Q. What’s the difference between useradd and usermod? A. useradd creates a brand-new user account, including options to create a home directory (-m) and set a login shell (-s). usermod instead modifies an account that already exists - adding it to another group (-aG) or renaming it (-l). A simple way to remember it: useradd for creating, usermod for changing.

Q. Why does /etc/passwd show x instead of the actual password hash? A. For security reasons, the real password hash is never stored directly in /etc/passwd. Instead it shows x, and the actual hash lives in /etc/shadow, which only the root user can read.

Q. How do I check which groups the current user belongs to? A. Run the id command. It prints all the groups the user is a member of, e.g. uid=1000(username) gid=1000(username) groups=1000(username),4(adm),27(sudo).

新しいLinuxの教科書 第2版(三宅英明・大角祐介、SBクリエイティブ)

More field-by-field book recommendations are collected in 10 Recommended Technical Books for Engineers .