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.
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 admin02 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 admin03 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 admin04 Delete User
userdel [-r] username
# -r remove home directory, -f force deletion
# example:
userdel -r adminLinux Group Management
01 Create Group
groupadd [options] groupname
-g set GID
# example:
groupadd -g 1008 test0102 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_test03 Delete Group
groupdel groupname
# example:
groupdel new_test04 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 adminCommon Commands to View User Information
id
id [options] [username]
# shows UID, GID and groups
# examples:
id test_user
id # current userwho
who
# lists currently logged‑in userswhoami
whoami
# prints current usernamelast
last
# shows login history from /var/log/wtmplastb
lastb
# shows failed login attempts from /var/log/btmplastlog
lastlog
# shows most recent login of each user from /var/log/lastloglast reboot
last reboot
# displays system reboot recordsOpen Source Linux
Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
