Linux Administrator

How to Add and Remove User Account in Linux

Linux is a multi-user operating system, which means that more than one user can use Linux at the same time. Linux provides a beautiful mechanism to manage users in a system. One of the most important roles of a system administrator is to manage the users and groups in a system.

In this article I will explain how to add and remove user account from command line in Linux System.

Adding New User to an Linux System

1. Run the below command to get the user manual.

# man useradd

2. Create the new user account with their home directory.

# useradd --home /home/sagar sagar


# adduser sagar

3. Useraddd command does not set any valid password by default, and user cannot log in until a password is set.To set the password user the following command:

# passwd sagar
Changing password for user sagar.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

4. Verify the values in /etc/password:

# cat /etc/passwd | grep sagar

5. Verify the values in /etc/group :

# cat /etc/group | grep sagar

6. Verify email user created for id sagar:

# ls /var/spool/mail | grep sagar

More other options:

-c, –comment COMMENT

Add a value, such as a full name, to the GECOS field.

-g, –gid GROUP

Specify the primary group for the user account.

-G, –groups GROUPS

Specify a list if supplementary groups for the user account.

-a, –append
Used with the -G option to append the user to the supplemental groups mentioned without removing the user from other groups.

-d, –home HOME_DIR
Specify a new home directory to a new location. Must be used with the -d option.

-m, –move-home
Move a user home directory to a new location. Must be used with the -d option.

s, –shell SHELL
Specify a new login shell for the user account.

-L, –lock
Lock a user account.

-U, –unlock
Unlock a user account.

Deleting User from Linux System

1. Run the below command to get userdel manual.

# man userdel

2. userdel username removes the user from /etc/passwd, but leaves the home directory intact by default. Proper command to remove the user’s account, user’s home directory and mail spool as part of the deletion process.

# userdel --remove sagar
# userdel -r sagar
When a user is removed with userdel without the -r option specified, the system will have files that are owned by an unassigned user ID number. This can also happen when files created by a deleted user exist outside their home directory. This situation can lead to information leakage and other security issues.
Thank you! for visiting LookLinux.

If you find this tutorial helpful please share with your friends to keep it alive. For more helpful topic browse my website To become an author at Look Linux Submit Article. Stay connected to Facebook.

About the author


Santosh Prasad

Hi! I'm Santosh and I'm here to post some cool article for you. If you have any query and suggestion please comment in comment section.

Leave a Comment