User and group management is one of the most important skills for any Linux system administrator.It’s essential for controlling who can access the system, what permissions they have, and how they interact with files and services.
In this blog, we’ll cover how to create, modify, and delete users and groups, set passwords, and manage privileges on Oracle Linux.
Step 1: Understanding Users and Groups
Linux:
-
A user represents a person or process that can log in and execute tasks.
-
A group is a collection of users that share permissions.
User and group details are stored in:
-
/etc/passwd → user account info
-
/etc/shadow → encrypted passwords
-
/etc/group → group info
To view these files:
cat /etc/passwd
cat /etc/group

Step 2: Creating a New User
Use the useradd command:
sudo useradd username
Example:
Now, set a password for the new user:

You’ll be prompted to enter and confirm the password.
Step 3: Creating a User with Custom Options
You can customize the user’s home directory, shell, and UID (user ID).
Example:
sudo useradd -d /data/joe_home -s /bin/bash joe
Explanation:
-
-d → custom home directory
-
-s → specifies login shell

Step 4: Modifying an Existing User
Change the username:
sudo usermod -l newname oldname
Change the home directory:
sudo usermod -d /new/home/path username
Add a user to an existing group:
sudo usermod -aG groupname username
Example:

(The “wheel” group allows administrative privileges using sudo.)
Step 5: Deleting Users
To delete a user but keep their files:
sudo userdel username
To delete the user and their home directory:

Step 6: Managing Groups
Create a new group:
sudo groupadd developers
Add a user to a group:
sudo usermod -aG developers joe
View group membership:
groups joe

Delete a group:
sudo groupdel developers
Step 7: Granting Sudo (Admin) Privileges
Users in the wheel group can run administrative commands with sudo.
Add a user to the wheel group:
sudo usermod -aG wheel joe
Verify:
groups joe
To test:
su - joe


Step 8: Understanding Important Files
|
File |
Description |
|
/etc/passwd |
Basic user info (username, UID, GID, home dir, shell) |
|
/etc/shadow |
Encrypted passwords and expiration data |
|
/etc/group |
Group names and member lists |
|
/etc/sudoers |
Who can run admin commands |
To safely edit sudoers:
sudo visudo
Add a line like:
joe ALL=(ALL) ALL

Step 9: Check User and Group Details
Display current logged-in user:
whoami
Show user details:
id username
Example:
uid=1001(joe) gid=1001(joe) groups=1001(joe),10(wheel)

Step 10: Locking and Unlocking Accounts
To temporarily lock a user:
sudo passwd -l joe
To unlock:
sudo passwd -u joe
Conclusion
You now know how to manage users and groups — one of the cornerstones of Linux administration. With these commands, you can securely manage access and assign the right privileges to each user.
In the next post, we’ll move on to file permissions and ownership, where we’ll control what users and groups can do with files and directories.
