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:

  1. Requirements
  2. Create a new user
  3. Grant root permissions for a user
  4. Remove an existing user

Requirements

CentOS 6.4, Debian or Ubuntu installed on your computer/server

SSH access (Command line access to the server)

root privileges

Basic skills for working on a Linux environment

Create a New User

CentOS 6.4:

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

Debian/Ubuntu:

During the user creation procedure you will be prompted to enter new password for it and provide some additional information:

sudo adduser username

Adding user username' ...
Adding new group
username' (1001) ...
Adding new user username' (1000) with group username' ...
Creating home directory /home/username' ...
Copying files from
/etc/skel' ...

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 []:

Other []:

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

or

sudo /usr/sbin/visudo

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