Linux User and Group Management Essentials

User Management

Creating Users

The useradd command creates new user accounts. By default, the system automatically generates a home directory under /home/ using the username.

useradd jerry

To specify a custom home directory path, use the -d option:

useradd -d /opt/custompath jerry

After creating a user, set or update the password with the passwd command:

passwd jerry

Removing Users

To delete a user account while preserving their home directory:

userdel marcus

To remove both the account and its home directory:

userdel -r marcus

Querying User Information

The id command displays detailed user information including UID, GID, and group memberships:

$ id administrator
uid=1001(administrator) gid=1001(administrator) groups=1001(administrator),4(adm),27(sudo)

Switching Users

The su command allows switching between user accounts. Switching to a lower priviledge level does not require a password, but moving to higher privilege does:

su - alice

Use exit or logout to return to the previous session.

User Groups

Groups function as role-based containers, enabling administrators to manage multiple users who share similar permission requirements.

Creating Groups

groupadd developers

Deleting Groups

groupdel developers

Asigning Groups During User Creation

useradd -g developers alice

This places the new user directly into an existing group. When no group is specified during user creation, the system automatically generates a private group bearing the same name as the user and adds the user to it.

Modifying User Groups

usermod -g developers alice

Configuration Files

/etc/passwd

This file stores user account information. Each line follows this format:

username:password:uid:gid:comment:home_directory:login_shell

Example entries:

root:x:0:0:root:/root:/bin/bash
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
alice:x:1001:1001:Alice Smith:/home/alice:/bin/bash

The shell field specifies the user's login interpreter. System accounts commonly use /usr/sbin/nologin or /sbin/nologin, which prevents interactive login even with valid credentials. These accounts can still access system resources programmatically but cannot establish terminal sessions.

/etc/shadow

This file contains encrypted passwords and account expiration policies:

username:encrypted_password:last_change:min_days:max_days:warn_days:inactive:expire:reserved

/etc/group

This file defines group information:

group_name:password:gid:members

Example:

staff:x:50:alice,bob
developers:x:1001:alice,charlie
alice:x:1001:alice

The members field lists users belonging to the group, though users may have this as a primary group without appearing in the list.

Tags: Linux user-management useradd usermod userdel

Posted on Sat, 16 May 2026 05:03:00 +0000 by andrewdunstall