Today we will talk about User management in Linux. I will explain all the important commands that helps in managing the user in Linux.
The first command to create a new user in Linux is “useradd“.
1. useradd
useradd command helps in creating the new user in the OS. Users use to manage the packages, directories and files in the system. It is the initial part of user management.

Format of the useradd command is useradd (name)
Examples: useradd root-learning, useradd john, useradd love etc.
2. passwd
passwd command helps in creating or changing the password of the user. It is a manual process to do from your side.

Format of the passwd command is passwd (user name)
Examples: passwd root-learning, passwd john, passwd love etc.
3. id
id command is used for checking the user is created or not in the system. We can also check for our own user details.

Format of the id command is id (user name)
Examples: id john, id love etc.
4. /etc/passwd
/etc/passwd is the file that holds all the details of user management. It has 8 fields that is username: passwd: uid: gid: comments: home directory: shell

Here in last entry of /etc/passwd file, user name is love: passwd is hidden as x: uid is 1003: gid is 1003: comment is empty: home directory is /home/love: shell is /bin/bash.
All the user details contains in /etc/passwd file for easy user management.
5. who
who command helps in checking all the logged in user. There are several commands with few more details that is finger, pinky, w etc.

Format of the who command is who
Example: who
6. usermod
usermod command helps in modify the features of the user. It is one of the important command in user management.

Format of the usermod command is usermod (options) (user name)
Example: usermod -d /tmp love (to change the home directory of user love to /tmp)
7. userdel
userdel command is use to delete the user from the system.

Format of the userdel command is userdel (user name)
Examples: userdel love, userdel john etc.
That’s all about User Management in Linux. Our new platform for Hosting plans will be ready soon, You can check out the plans from here.
FAQ on User Management in Linux
Q. How do I create a new user in Linux?
A. You can create a new user by running the following command:
useradd (username)
Q. How do I create a password for new user in Linux?
A. To set a password for the new user:
passwd (username)
Q. How can I delete a user in Linux?
A. To remove a user, use the following command:
userdel (username)
If you want to delete the user and their home directory, add the -r option:
userdel -r (username)
Q. How do I list all users in Linux?
A. You can list all users by viewing the contents of the /etc/passwd file:
cat /etc/passwd
Each line represents a user.
Q. How can I change a user’s password?
A. To change the password for a user:
passwd (username)
Then follow the prompts to enter the new password.
Q. How do I add a user to a group in Linux?
A. Use the usermod command to add a user to a group:
usermod -aG (groupname) (username)
The -aG option appends the user to the specified group without removing them from other groups.
Q. How do I check which groups a user belongs to?
A. To list the groups a user is part of, use the groups command:
groups (username)
Q. What is the difference between a user and a superuser?
A. A user is a regular account on the system, while a superuser (root) has elevated privileges allowing them to perform system-wide tasks. The root user can access, modify and configure anything on the system.
Discover more from Root Learning
Subscribe to get the latest posts sent to your email.