User Management
Overview
Linux is a multi-user operating system, and user management is one of the core tasks of system administration. This chapter introduces the concepts, creation, modification, and deletion of users and groups.
User and Group Concepts
User Types
User Related Files
/etc/passwd Format
/etc/shadow Format
/etc/group Format
Viewing User Information
id - User ID Information
whoami - Current Username
who - Logged-in Users
w - User Activity
last - Login History
groups - User's Groups
Creating Users
useradd - Add User
adduser - Interactive Creation (Debian Family)
Setting Password
Modifying Users
usermod - Modify User
chsh - Change Shell
chfn - Modify User Information
Deleting Users
userdel - Delete User
deluser (Debian Family)
Group Management
Create Group
Modify Group
Delete Group
Managing Group Members
Password Management
passwd - Password Operations
chage - Password Expiration Policy
sudo Permissions
Configuring sudo
Edit /etc/sudoers (using visudo):
Adding User to sudo Group
Using sudo
Switching Users
su - Switch User
sudo su vs su
Practical Tips
Batch Create Users
Find Users Without Passwords
Find UID 0 Users
List All Regular Users
Summary
This chapter introduced Linux user management:
- User operations:
useradd,usermod,userdel - Group operations:
groupadd,groupmod,groupdel - Password management:
passwd,chage - sudo permissions: Configuring and using sudo
- User switching:
su,sudo su
Good user management is foundation of system security. Follow principle of least privilege - grant only necessary permissions.
Previous chapter: Regular Expressions
Next chapter: Process Management