How to add and delete users in CentOS 6.4, Debian or Ubuntu
In this tutorial we will cover the steps needed to create new create new users, grant root access for them and delete them in CentOS 6.4, Debian or Ubuntu platform.
Table of contents:
- Create a new user
- Grant root permissions for a user
- Remove an existing user
CentOS 6.4, Debian or Ubuntu installed on your computer/server
SSH access (Command line access to the server)
Basic skills for working on a Linux environment
Create a New User
We can add new regular user with the following command:
sudo adduser username
where username is the name of the user which we want to add.
Hit enter and the new user will be created as well as its home folder /home/username.
You can set password for the new user with the following syntax:
sudo passwd username
During the user creation procedure you will be prompted to enter new password for it and provide some additional information:
sudo adduser username
username' ...username' (1001) ...
Adding new group
Adding new user
username' (1000) with group username' ...
Creating home directory
/home/username' .../etc/skel' ...
Copying files from
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for username
Enter the new value, or press ENTER for the default
Full Name :
Room Number :
Work Phone :
Home Phone :
Is the information correct? [Y/n] y
After that you should be able to access the system with the newly created login credentials.
Grant root Permissions for an User
In order to grant specific user with the root privileges we need to add the user to the sudoers file:
sudo nano /etc/sudoers
Find the following lines inside the file:
# User privilege specification
root ALL=(ALL:ALL) ALL
and add the same line for the corresponding user:
username ALL=(ALL:ALL) ALL
Save the file in order for the changes to take effect.
Remove an existing user
We can delete an existing username with the following command:
sudo userdel username
where username is the name of the user which we want to delete.
If we want to remove the user's home folder as well we can use the -r option:
sudo userdel -r username