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

1 Comment

Anon Linuxer (not verified)
February 19th, 2010 01:19 pm
Many distros recommend using adduser and deluser over useradd and userdel.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.