How to Create and Manage Users in Linux
How to Create and Manage Users in Linux
User management is one of the most fundamental tasks for any Linux system administrator. Whether you're running a multi-user server or just managing your personal Linux machine, understanding how to create, modify, and remove users is essential.
In this post, we’ll walk through the basic commands and best practices for creating and managing users on a Linux system.
Why User Management Matters
User accounts help control access to resources. By assigning specific permissions and groups, you can ensure the right users have the right access — and nothing more. It’s key for:
Security
System auditing
Collaboration
Resource management
Creating Users
useradd – The Standard Way to Add Users
The most common command to add a user is useradd.
This creates a user called john but doesn’t set a password yet.
Setting a Password
sudo passwd john
You’ll be prompted to enter a password for the user.
Creating a User with a Home Directory
By default, useradd might not create a home directory on some systems. Use the -m option:
sudo useradd -m john
This creates /home/john and copies default files from /etc/skel.
Creating a User with Specific Shell
sudo useradd -m -s /bin/bash john
This assigns /bin/bash as the default shell.
Modifying Users
usermod – Modify Existing User Accounts
Change username:
sudo usermod -l newname oldname
Change home directory:
sudo usermod -d /new/home john
Add user to a group:
sudo usermod -aG sudo john
Deleting Users
userdel – Remove User Accounts
Remove a user:
sudo userdel john
Remove user and their home directory:
sudo userdel -r john
Listing Users
To view all users on the system:
cut -d: -f1 /etc/passwd
For active sessions:
who
Checking User Details
Use id to get UID, GID, and groups:
id john
To list user’s groups:
groups john
Best Practices for User Management
Always assign strong passwords.
Use groups to manage permissions efficiently.
Regularly audit users and remove inactive accounts.
Avoid logging in as root directly — use sudo.
Conclusion
Managing users in Linux is a vital skill that ensures system security and organization. With commands like useradd, usermod, and userdel, you're fully equipped to handle users effectively on any Linux distribution.
Continue Reading
- 25 Essential Linux Commands Every Sysadmin Must Know
- 10 Basic Linux Commands Every Beginner Should Know
- Linux for DevOps: Why It’s Essential and What You Need to Learn
Get structured, hands-on Linux and DevOps training at
Unix Training Academy