Operations 8 min read

Master Linux User & Group Management: Commands, Tips, and Best Practices

This guide explains Linux user and group concepts, shows how to create, modify, and delete users and groups with commands like useradd, usermod, groupadd, and gpasswd, and lists essential commands for viewing user information such as id, who, last, and lastlog.

Open Source Linux
Open Source Linux
Open Source Linux
Master Linux User & Group Management: Commands, Tips, and Best Practices

Introduction

Linux is a multi‑user, multitasking operating system that allows multiple users to log in simultaneously, each running independent tasks.

User and Group Concepts

Linux manages users and groups via numeric IDs. The user ID (UID) identifies a user, while the group ID (GID) identifies a group. UID 0 is the super‑admin (root). Users fall into three categories:

root user (ID 0)

system users (ID 1‑499)

regular users (ID 500‑60000)

Groups consist of a primary group and optional supplementary groups; a user can belong to one primary group and multiple supplementary groups. By default, creating a user also creates a group with the same name and makes the user a member of that primary group.

Linux User Management

01 Create User

useradd [options] username
# common options:
-c  set comment (usually full name)
-d  set home directory (default /home/username)
-e  set expiration date (YYYY‑MM‑DD)
-g  set primary group
-G  set supplementary groups (comma‑separated)
-M  do not create home directory
-s  set login shell (default bash)
-u  set UID
# examples:
useradd -s /sbin/nologin -M user01
useradd -c administrator -d /home/admin -e 2020-03-11 -g root -G mail,bin admin

02 Modify User Attributes

usermod [options] username
# common options:
-d  change home directory
-e  change expiration date
-g  change primary group
-G  change supplementary groups
-s  change login shell
-u  change UID
# examples:
usermod -d /home/nginx nginx01
usermod -u 1005 admin
usermod -s /sbin/nologin admin

03 Change User Password

passwd [options] [username]
# options:
-l  lock account (root only)
-u  unlock password
-d  delete password (root only)
--stdin  read password from stdin
# examples:
echo "abc123" | passwd --stdin admin
passwd -l admin

04 Delete User

userdel [-r] username
# -r remove home directory, -f force deletion
# example:
userdel -r admin

Linux Group Management

01 Create Group

groupadd [options] groupname
-g  set GID
# example:
groupadd -g 1008 test01

02 Modify Group

(1) Rename group:

groupmod -n newname oldname
# example:
groupmod -n new_test test01

(2) Change GID:

groupmod -g newGID groupname
# example:
groupmod -g 1002 new_test

03 Delete Group

groupdel groupname
# example:
groupdel new_test

04 Manage Group Membership

gpasswd -a user group   # add user to group
gpasswd -d user group   # remove user from group
gpasswd -A user group   # set user as group admin
# examples:
gpasswd -a test_user admin
gpasswd -d test_user admin
gpasswd -A test_user admin

Common Commands to View User Information

id

id [options] [username]
# shows UID, GID and groups
# examples:
id test_user
id   # current user

who

who
# lists currently logged‑in users

whoami

whoami
# prints current username

last

last
# shows login history from /var/log/wtmp

lastb

lastb
# shows failed login attempts from /var/log/btmp

lastlog

lastlog
# shows most recent login of each user from /var/log/lastlog

last reboot

last reboot
# displays system reboot records
group-managementcommandssystem-administrationuser-management
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.