How to add/remove User accounts in Linux?
Most of us need to work with creating/managing user accounts on a regular basis. System Administrators have to deal with this stuff on a regular basis. In this howto i will go through the basics of creating and deleting user accounts on a Linux-based system.
Most of the people use root for their day to day tasks, this is not safe. Instead, we should use root to create a user and then work as that user.
Adding a User
To add new users just use this simple command
[root]# useradd chia
Please note that, you may find adduser and deluser as the preferred commands in some distros documentation. You can read about the difference between adduser & useradd here.
To give a password to this user
[root]# passwd chia
If you want to assign a particular Home directory to the user you can do that using this command.
[root]# useradd chia -d /home/chia
Removing a User
Now we learn how to create and modify users. Now we will look at how we will delete the users.
[root]# userdel chia
This will remove the user. But if you want to remove their home folder and all their files.
[root]# userdel -r chia
Wondering where is this info stored. Well, there is a file /etc/passwd where you can find info about all the users. Every user is allowed to read the contents of the file but only root has the permission to do changes in that file. In this file system accounts' information is stored like User ID, group ID, homedir etc. The format is like this.
User - Username used for logging on or by a program
x - This field used to contain information to validate user's password. However, in modern systems it is mostly set to x with the actual encrypted passwd saved in /etc/shadow file. Setting the 'x' to '*' is used to deactivate an account.
UID - The User ID. The unique ID of a user, root is UID 0. It determines the ownership of system and processes.
GID - Group id for primary group of user. Every user has atleast one GID. User can be assigned to several groups. The GID and UID are very important for linux filesystem.
homedir - This represent the home directory for the user. Default is more than ok most of the time.
So as you can see there is a lot of things stored in /etc/passwd.
This article is about adding/removing users using a command line. If you are looking for a GUI method, see add/remove users using a GUI