How to Manage Linux Users and Groups from the Terminal

Use Linux’s account tools to create users, organize permissions with groups, and remove access when it is no longer needed. The commands below work on many distributions that use the standard Shadow utilities. Run them with sudo; if your system does not use sudo, become root with su - and omit sudo from each command. Examples use maya as a username and developers as a group.

Check a user’s groups first

A user has a primary group and can also belong to supplementary groups. Groups let you grant shared access to files or services without changing each file’s owner. Before editing an account, inspect its current IDs and memberships:

id maya
groups maya
getent group developers

id shows user and group IDs; groups lists membership names. getent queries the configured group database, including network directories when configured, so it is more reliable than searching only /etc/group. These local commands do not administer directory-managed accounts; update those through your identity service.

Linux terminal output showing a user’s group IDs and a getent lookup for the developers group
Check a user’s current memberships and confirm whether a group exists.

Create or remove a group

Create one group by passing one group name to groupadd:

sudo groupadd developers
getent group developers

Run groupadd once per group. A comma-separated list is not a way to create several groups; it is accepted by some other commands, such as the -G option for assigning a user to multiple groups. Group names should follow your distribution’s naming rules.

Linux terminal creating the developers group with groupadd and confirming it with getent
Create a group, then look it up by name.

Remove an unused group with sudo groupdel oldgroup. First confirm that no user has it as a primary group; move those users to an appropriate group before retrying. Check for files owned by the group, too. Deleting it does not change file ownership, and its files may show only a numeric group ID. Avoid force options that bypass these checks.

Linux terminal removing the contractors group with groupdel and checking that it no longer resolves
Remove a group only after checking primary-group and file ownership dependencies.

Add or remove a user from a group

To add an existing user to a supplementary group while keeping their other memberships, use usermod with both -a and -G:

sudo usermod -aG developers maya
id maya

The -a means “append.” Without it, -G replaces the supplementary-group list and can remove existing access. Verify with id maya. The user must start a new login session to pick up the change; running processes keep their current group credentials.

Linux terminal using usermod with the append option to add maya to developers and verifying with id
Append the new group, then verify the full membership list.

To remove one user from one supplementary group without replacing the rest of their groups, use:

sudo gpasswd -d maya developers
id maya

For an access-sensitive removal, end the user’s active sessions or restart affected services; existing processes may retain the old group list.

Linux terminal removing maya from the developers group with gpasswd and checking her remaining groups
Remove only the selected membership and confirm what remains.

Create a user account

On systems with Shadow’s useradd, the following creates a home directory and a same-named primary group:

sudo useradd -m -U maya
sudo passwd maya
id maya
getent passwd maya

-m creates the home directory, and -U requests a same-named primary group. You can add -s /path/to/shell if you need a specific installed shell. passwd prompts for a password without displaying the characters. Some distributions provide an interactive adduser command instead; check local documentation if an option is unavailable.

Linux terminal creating the maya account with useradd, a home directory, and a same-name group
Create a regular account with an explicit home directory and primary group.
Linux terminal setting a password for maya and verifying the new account with id
Set a password interactively and check the account’s IDs.

Delete a user safely

Before removing an account, confirm its owner, save files or mail that must be retained, stop services or scheduled work running as that user, and have them sign out. Never delete the account you are currently using.

To remove the account entry but keep its home directory, run:

sudo userdel maya

To also remove the home directory and the configured mail spool, use -r:

sudo userdel -r maya
getent passwd maya

With -r, the home directory and mail spool are deleted; files elsewhere are not automatically removed. Back up needed data first, then search for leftover files owned by the account. Avoid -f, which skips safety checks and can leave inconsistencies.

Linux terminal deleting maya and her home directory with userdel -r, then checking the account database
The -r option removes the home directory, so confirm backups before using it.

Quick troubleshooting

  • “Permission denied”: use sudo if authorized, or switch to root.
  • Name already exists: check with getent group name or getent passwd name.
  • Access has not changed: start a new login session and confirm whether the app uses centralized identity.

For option details and distribution-specific behavior, consult the groupadd manual, groupdel manual, usermod manual, useradd manual, userdel manual, gpasswd manual, and getent manual.

Leave a Comment

How to Record Speaker Output on Linux with Audacity

How to Record Speaker Output on Linux with Audacity

Capture Linux desktop audio in Audacity by routing its recording stream to your output device’s monitor source. Follow PulseAudio and PipeWire steps, export tips, and fixes for silent tracks.

How to Use Dropbox on Linux: Install and Sync Your Files

How to Use Dropbox on Linux: Install and Sync Your Files

Install Dropbox on Linux from the official package, sign in, sync a local folder, manage selective sync, and check status from the command line.

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

How to Install Inkscape on Linux: Ubuntu, Fedora, Arch, and More

Install Inkscape from your Linux distribution’s repositories, the Ubuntu stable PPA, Snap, or Flathub, with current commands and notes for choosing a package source.

How to Find and Remove Duplicate Files on Linux With FSlint

How to Find and Remove Duplicate Files on Linux With FSlint

Use FSlint to scan selected Linux folders, review duplicate groups, and safely delete redundant files or learn when hard-link merging is appropriate.

How to Install SABnzbd on Linux and Configure It

How to Install SABnzbd on Linux and Configure It

Install SABnzbd on Ubuntu or Debian, or run it in Docker on another Linux host. Then open the web interface and configure your provider and download folders.

How to Install the Paper GTK Theme on Linux

How to Install the Paper GTK Theme on Linux

Install the Paper GTK theme from supported Linux repositories, enable it for GTK apps in GNOME Tweaks, and see what the legacy theme can and cannot change.

How to Install and Set Up Plex on OpenMediaVault with Compose

How to Install and Set Up Plex on OpenMediaVault with Compose

The old OpenMediaVault Plex plugin is archived. Set up Plex on OMV 8 with OMV-Extras, the Compose plugin, persistent storage, and Plex’s official container.

How to Clean and Speed Up Ubuntu Safely

How to Clean and Speed Up Ubuntu Safely

Clean and speed up Ubuntu with safe APT cleanup, storage checks, and startup controls that help free space and troubleshoot a sluggish desktop.

How to Install the Hiri Email Client on Linux

How to Install the Hiri Email Client on Linux

Install Hiri on Linux with its Snap package or official tarball, add a desktop launcher, and check supported accounts plus a warning about Hiri’s old Snap release.

How to Get System Specifications for a Linux PC

How to Get System Specifications for a Linux PC

Use Fastfetch and built-in Linux commands to check your distro, kernel, CPU, memory, graphics, storage, and connected devices, then save a clear report.