How to Add and Remove User Account in Linux
How to Add and Remove User Account in Linux
Linux is a multi-user operating system, which meant to be 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, we are going to see 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/webuser webuser
Or
# adduser webuser
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 webuser Changing password for user webuser. New password: Retype new password: passwd: all authentication tokens updated successfully.
4. Verify the values in /etc/password:
# cat /etc/passwd | grep webuser webuser:x:501:501::/home/webuser:/bin/bash
5. Verify the values in /etc/group :
# cat /etc/group | grep webuser webuser:x:501:
6. Verify email user created for id webuser:
# ls /var/spool/mail | grep webuser webuser
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 webuser Or # userdel -r webuser