Operations 15 min read

Master Linux User and Group Management: Commands, Files, and Best Practices

This guide explains how Linux stores user and group information in /etc/passwd, /etc/shadow, and /etc/group, and provides detailed usage of commands such as useradd, usermod, userdel, groupadd, groupmod, and gpasswd for creating, modifying, locking, and deleting accounts and groups.

MaGe Linux Operations
MaGe Linux Operations
MaGe Linux Operations
Master Linux User and Group Management: Commands, Files, and Best Practices

1. User and Group Files

Linux stores user accounts, passwords, group information, and group passwords in separate configuration files. User account details (except passwords) are in /etc/passwd, while encrypted passwords reside in /etc/shadow. The /etc/group file holds group names and member lists, and /etc/gshadow stores group passwords.

2. Password File

For security, real passwords are MD5‑hashed and saved in /etc/shadow, readable only by root. Like /etc/passwd, each line in /etc/shadow represents one account, with the first field as the username and the second as the password hash.

3. Group Account File

Group information is kept in /etc/group. The first field is the group name, the second is an x placeholder, the third is the GID, and the fourth lists member usernames separated by commas.

4. Adding Users

Use useradd [options] username to create a new user. Common options include: -c comment -d home directory -m create home directory -M do not create home directory -e account expiration date -f days after expiration before disabling -g primary group -G supplementary groups -n no private group -s login shell (default /bin/bash) -r system account (UID < 500) -u specify UID -p password hash (rarely used)

Example:

[root@localhost ~]# useradd -g babyfish nisj
[root@localhost ~]# id nisj

If -g is omitted, a private group with the same name as the user is created; use -n to suppress this.

5. Setting Account Attributes

Modify existing accounts with usermod [options] username. Key options: -l new_name change login name -d new_home change home directory -L lock account (adds ! to password field) -U unlock account

Example of renaming and moving home directory:

[root@localhost ~]# usermod -l nsj0820 nsj820
[root@localhost ~]# usermod -d /home/nsj0820 nsj0820

6. Deleting Accounts

Remove a user with userdel [-r] username. The -r flag also deletes the user’s home directory.

7. Setting User Login Password

Root can set any account’s password with passwd username. Regular users can change only their own password by running passwd without arguments.

8. Locking/Unlocking Passwords and Querying Status

Lock a password with passwd -l username and unlock with passwd -u username. Check status using passwd -S username.

9. Creating User Groups

Create a group with groupadd [-r] groupname. The -r option creates a system group (GID < 500).

10. Modifying Group Attributes

Rename a group: groupmod -n newname oldname. Change GID: groupmod -g newGID groupname.

11. Deleting User Groups

Delete a group with groupdel groupname. The group must not be a private group of any existing account.

12. Adding/Removing Users to/from Groups

Use gpasswd -a username groupname to add and gpasswd -d username groupname to remove a user from a group.

13. Setting Group Administrator

Assign a group admin with gpasswd -A username groupname. The admin can manage members of that group but not other groups.

14. Other Useful Commands

Commands such as id, whoami, and groups display user and group information. Graphical tools are also available via System → Administration → Users and Groups.

Note: When adding a user to a group, always use the -a (append) option with usermod -G to avoid removing the user from existing groups.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

System AdministrationUser Managementgroup-management
MaGe Linux Operations
Written by

MaGe Linux Operations

Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.

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.