User Management Commands in Linux
Introduction
User management is a critical aspect of Linux system administration. Whether you’re managing a personal server or a multi-user environment, knowing how to create, modify, and manage users ensures smooth operation and security. In this blog, we’ll cover the essential Linux commands for user management.
1. Creating Users
adduser
: Creates a new user with default settings.
Example:sudo adduser username
Use Case: Sets up a user with a home directory and default shell.
useradd
: Adds a user with more flexibility but fewer defaults.
Example:sudo useradd -m username
Use Case: Ideal for customized user creation.
2. Deleting Users
deluser
: Removes a user from the system.
Example:sudo deluser username
userdel
: Deletes a user and optionally their home directory.
Example:sudo userdel -r username
Note: Use
-r
carefully to avoid losing important data.
3. Modifying Users
usermod
: Modifies an existing user’s settings.
Examples:sudo usermod -c "New Name" username # Add or update comment sudo usermod -aG groupname username # Add to a group
passwd
: Sets or updates a user’s password.
Example:sudo passwd username
Use Case: Ensures password security and updates.
4. Managing Groups
groupadd
: Creates a new group.
Example:sudo groupadd groupname
groupdel
: Deletes a group.
Example:sudo groupdel groupname
gpasswd
: Adds users to a group.
Example:sudo gpasswd -a username groupname
Use Case: Groups simplify permissions management.
5. Viewing User Information
id
: Displays a user’s ID and group memberships.
Example:id username
who
: Shows logged-in users.
Example:who
w
: Displays detailed information about logged-in users and their activities.
Example:w
6. Advanced User Management
chage
: Manages password expiry for a user.
Example:sudo chage -l username
su
: Switches to another user account.
Example:su - username
sudo
: Executes commands with superuser privileges.
Example:sudo command
Conclusion
User management is vital for maintaining a secure and efficient Linux system. By mastering these commands, you’ll be able to handle user accounts, groups, and permissions with ease. Practice them on your Linux system and take control of your user environment.
Happy learning!!!
Subscribe to my newsletter
Read articles from Nithin Kumar C A directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by