4

How to add/remove User accounts in Linux?

view full story
linux-howto

http://linuxers.org – 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 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, encrypted passwd etc. The format is like this. user:password:UID:GID:comment:homedir:shell e.g root:x:0:0:root:/bin/bash User - Username used for logging on or by a program Password - Encrypted password is stored here 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 (General)