Linux System User and Group Management Tutorial
This tutorial explains Linux user and group management, covering login prompts, user information commands, adding, modifying, and deleting users, switching users, password handling, file permission changes, and group administration with practical command examples and code snippets.
This article provides a step‑by‑step guide to managing users and groups on a Linux system, beginning with an overview of login prompts and the distinction between the root ( # ) and regular user ( $ ) symbols.
It introduces basic user‑information commands such as id (showing UID and GID) and whoami (displaying the current username).
The adding users section describes the useradd command and its common options:
-d specify home directory
-M do not create a home directory
-u set UID
-g set GID
-s set login shell
Example of creating a default user:
useradd xiaoxuThe resulting entry in /etc/passwd looks like:
xiaoxu:x:1004:1004::/home/xiaoxu:/bin/bashIt also shows how to list available shells with cat /etc/shells and explains that /sbin/nologin disables login for a user.
Practice commands for adding users with specific options are provided, e.g.:
useradd xiaob -u 1009 -g 1004 -M -s /sbin/nologinFile‑viewing utilities such as head -5 /etc/passwd and tail -5 /etc/passwd are demonstrated.
The user switching section covers the su command, showing how to switch to another user ( su xiaoxu ), run a single command as another user ( su xiaoxu -c id ), and exit back to the original session ( exit ).
Deletion of users is performed with userdel . The article notes that userdel xiaoc removes the account but leaves the home directory, while userdel -r xiaod removes both the account and its home directory.
Modifying user attributes uses usermod :
-d change home directory
-g change primary group
-s change login shell
Examples:
usermod -d /opt/xiaoc xiaoc usermod -g 1004 xiaoc usermod -s /bin/bash xiaobPassword management is covered with the passwd command, which edits the /etc/shadow file. An example session shows changing the root password.
The permission management part explains user categories (administrator, regular user, system user) and the chown command for changing file ownership, including examples for changing user, group, or both.
Group management is introduced with groupadd to create groups, groupdel to delete them, and the /etc/group file as the configuration source.
Overall, the tutorial combines explanatory text with concrete command‑line examples to equip readers with the skills needed for effective Linux user and group administration.
DevOps Cloud Academy
Exploring industry DevOps practices and technical expertise.
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.