Linux Commands and Scripts

Learn Basic User Management in Linux

Do you want to add, modify or delete a user in Linux? Here is the perfect article for you.

Here are the basics process of adding, modifying and deleting a user. You will also learn to add a user in a group and to give user id with a single command.

Add the user by mentioning a group name and giving user ID:

# useradd -G [GROUPNAME] -u [USER_ID] [USERNAME]

-G – mention group name by comma-separated.
-u – assigning an available user ID. The value must be non-negative.

Modify user by adding into a new group or giving new user id:

usermod -aG [groupname] -u [user ID] [Username]

-a – append. Add user to the supplementary group(s).
-G – group name
-u – assigning an available user ID. The value must be non-negative.

Create a user’s home directory:

usermod -d [Username]

-d – The user’s new login directory.

To delete a user:

userdel -r [username]

-r – it will remove files in the user’s home directory along with the user’s mail spool.

Related Articles