User CRUD commands

Last Updated : 29 Jan, 2026

Managing users is the foundation of Linux system security. It is not just about typing commands; it is about managing the entries in the system's "database" files: /etc/passwd and /etc/shadow.

Where Users Live

Before running commands, understand where the data goes. Linux stores user data in plain text files.

  1. /etc/passwd: Stores public user info (Name, ID, Home Directory, Shell).
  2. /etc/shadow: Stores encrypted passwords and expiration data.
  3. /etc/group: Stores group memberships.

Anatomy of a User Entry (/etc/passwd):

john:x:1001:1001:John Doe:/home/john:/bin/bash
  • john: Username
  • x : Password placeholder (stored in shadow)
  • 1001 : User ID (UID)
  • 1001 : Group ID (GID)
  • /home/john : Home Directory
  • /bin/bash : Default Shell

1. Creating Users (adduser or useradd):

Creating a new user involves assigning a username, user ID (UID), primary group ID (GID), home directory, and login shell. Linux provides two commands for this purpose: adduser and useradd.

Using adduser:

sudo adduser new_username

The adduser command is a high-level, user-friendly script. It automatically:

  • Creates the home directory
  • Assigns default groups
  • Sets up user configuration files
  • Prompts for password and user details

Using useradd:

sudo useradd new_username

The useradd command is a low-level system utility. By default, it:

  • Creates the user entry but does not create a home directory
  • Does not prompt for a password
    Additional options (such as -m) are required for full setup.

2. Reading User Information (finger or id):

To retrieve information about a user, Linux provides commands such as finger and id.

Using finger:

finger username

This command displays detailed user information such as login name, home directory, shell, and last login (if the finger package is installed).

Using id:

id username

This command displays the user ID (UID), group ID (GID), and all groups the user belongs to.

3. Updating User Information (usermod):

The usermod command is used to modify user account attributes, such as the home directory, login shell, username, UID, or group memberships.

Example: Changing User's Home Directory:

sudo usermod -d /new/home/directory username

This command updates the home directory path for the specified user (it does not automatically move existing files unless used with additional options).

4. Deleting Users (deluser or userdel):

When a user account is no longer required, it can be removed using deluser or userdel.

Using deluser:

sudo deluser username

The deluser command is a higher-level utility that removes the user account and can optionally remove the home directory if specified.

Using userdel:

sudo userdel username

This command deletes the user account but does not remove the home directory by default.
To remove the home directory as well:

sudo userdel -r username

Additional Tips:

Adding Users to Groups (usermod or gpasswd):

sudo usermod -aG groupname username

OR

sudo gpasswd -a username groupname

These commands add an existing user to an existing group without removing them from other groups.

Changing User Password (passwd):

sudo passwd username

This command allows an administrator (or the user themselves) to set or change the user’s password.

Summary Cheatsheet

GoalCommand
Create (Interactive)sudo adduser bob
Create (Standard)sudo useradd -m -s /bin/bash bob
Set Passwordsudo passwd bob
Grant Admin/Sudosudo usermod -aG sudo bob
Check Groupsid bob
Delete (Wipe)sudo userdel -r bob
Comment