How to Add and Delete Users on an Ubuntu 14.04 VPS

This tutorial teaches you to add and delete users on an Ubuntu 14.04 VPS. If you are logging into your server for the first time, you will have to log in using the root user credentials. However, you have to create new users for accessing the virtual server for many reasons. For example if there are other individuals who needs to access the virtual server, you can create new users for them. It is recommended to grant root privileges for the newly creates users so that they have administrative capabilities in the virtual server.

While performing any commands or tasks with the newly created user, always remember to use the ‘sudo’ option. This is highly recommended for two reasons:

  1. It will prevent the user from making any system errors.
  2. It will store all the commands with ‘sudo’ option in a log file (‘/var/log/secure’) for auditing, in case if needed.

 

Adding a New User on Ubuntu 14.04 VPS

 

Once you are connected to the server using root credentials, you can create a new user for the server by issuing the following command:

adduser newuser

In case if you have logged in as a regular user other than root, you still can create a new user with the sudo option.

sudo adduser newuser

While creating a new user, you will be asked to enter few details like password, and other information about the user. You should set a password for the user and confirm it. Entering other information is optional and you can skip by pressing Enter.
 

Granting Privileges for New User

 

Now that you have created a new user for the server, lets grant root privileges  for performing root tasks. For that, you can use the ‘visudo’ command which will open the configuration file for editing. Since you are still logged in as root user, just type in the following:

visudo

 

If you are logged in as a regular user, you can type:

sudo visudo

 

The configuration file will be opened up. In that, search for ‘user privilege specification’ and add the following line to it below the root:

newuser ALL=(ALL:ALL) ALL

Your configuration file should like similar to this:

# User privilege specification
root    ALL=(ALL:ALL) ALL
newuser       ALL=(ALL:ALL) ALL

Save and exit the file by pressing ‘ctrl x’ and ‘Y’ and Enter.

Now you will be able to execute commands which needs administrative privileges. Make sure that you add ‘sudo’ to the beginning of the command.

 

Deleting a User on Ubuntu 14.04 VPS

 

In case if you want to delete a specific user from the virtual private server, you can do that by typing in the following command:

deluser newuser

The above command assumes that you are logged in as root user. If you are logged in as regular user, then use the following command:

sudo deluser newuser

these commands will delete the user account without deleting any of user’s files or directories. To delete the user’s home directory, you can use the command:

deluser --remove-home newuser

or

sudo deluser --remove-home newuser

as used by regular user.

You may also update the configuration file that we modified earlier to delete the corresponding line for the deleted user.

support2 has written 111 articles

Leave a Reply