Linux User Management

From wiki-ben
Jump to: navigation, search


Basic user creation and account manipulation is relatively easy with a number of simple commands

Command Purpose Syntax Use
adduser Creates a user account adduser <username>
passwd Assigns a password to a user account passwd <username>
userdel Deletes user account. Does not delete content userdel <username>

File Locations

Linux stores its user account and password hashes in two seperate files located on the file system.

The /etc/passwd file stores all of the user accounts on the system
The /etc/shadow file stores all of the hashes of the passwords to each account on the system



adduser adds a user to the system. This user account though is unaccessible as no password has been assigned to it, but can be identified as a valid user through ssh login or virtual login when logging into linux in non-gui mode. Note this step will create the user accounts home directory under /home/<username>

Create a user by entering:

adduser <username> 

Creating a user who also has sudo capabilities can be done simply by entering:

adduser <username> sudo

Adding users to any group can be done in the same way. To remove a user from a group, see userdel


After adding a user, you should immediately add a password, thus giving access to the account

Add a user by entering:

passwd <username>

You will then be prompted to enter a password and possibly warned if it is not strong enough, you can choose to ignore this warning if you would like


userdel will delete the user's account but does not delete any of the user's data or content stored in their home folder. This function acts as a method of disabling the user account.

To disable/delete a user account enter:

userdel <username>

Sometimes if the user is currently active or a program is using that user, userdel will prompt an error from the disable/delete. You can confirm and check this by running this command

w <username>

This will list all processes that are being used by the user or using the user for executing their commands. By either killing all processes using the user, or using -f flag to force the user to be deleted, userdel will then disable the account

To fully delete an account you will need to delete the user's data folder in /home/<username

This can be done cautiously with the following command

cd /home
rm -rf <username>

Note we are using the remove function but also have navigated to the /home folder. All we are doing here is forcing and recursively deleting the user's data folder from the /home folder

Alternatively, userdel can also be used to remove users from groups. You can list all groups a user is in with the following command

groups <username>

Simply, remove the user from a group with the following command

userdel <username> <usergroup>