Adding and deleting users is one of the core things to be done after launching a new Linux server as it is not advisable to give various users access to the root account.

Sudo (short for Super-user do) Access allows users to execute commands with the security privileges of another user, by default the root user.

In this guide, we are going to go through the steps of adding, deleting and granting sudo access to users on a Debian 9 server.

Deploying your cloud server
If you have not already registered with Cloudwafer, you should begin by getting signed up. Take a moment to create an account after which you can easily deploy your own cloud servers.

Once you have signed up, log into your Cloudwafer Client Area with the password provided in your mail and deploy your Cloudwafer cloud server.

Updating System Packages
It is always recommended that you update the system to the latest packages before beginning any major installations. This is done with the command below:

sudo apt-get update && sudo apt-get upgrade

Note: Commands used in this guide except specified with the sudo prefix before the command was issued as the root user.

Step 1: Adding a New User Account
Issue the command below to create a new user account using the adduser command. Don’t forget to replace ayodele with your desired user name:

adduser ayodele

As shown above, you will be prompted to enter a password for the new account and also confirm the new password. You will also be prompted to enter certain information about the user account (Full name, Room Number, Work Phone, Home Phone and Other). This is optional so you can proceed to press the ENTER key for the default.

Step 2: Adding users to the sudo group
By default on Debian systems, members of the group sudo are granted with sudo access. To add a user to the sudo group use the usermod command replacing ayodele with the name of the user

usermod -aG sudo ayodele

Step 3: Testing Sudo Access
After granting sudo access, we can test by carrying out a command that only a root user can perform. First, we need to switch to the user by typing:

su ayodele

Typing cd moves the working directory to the home account of ayodele.

We can now test by adding "sudo" to the beginning of the command that you want to run with sudo access which in this case is to install a package which is can only be done by the root user.

If you receive the bash: sudo: command not found error, or -su: sudo: command not found error. Issue the command to install sudo as the root user.

apt install sudo

Next, we can then proceed to test Sudo.

sudo apt-get install nginx

With the above message, we have successfully granted sudo access to the user account.

Step 4: Deleting a User Account
In cases where a user account is no longer needed, it is always advisable to delete the old account. As root (and adding sudo if you have sudo access on another user account), you can delete the user account itself, without deleting any of the user's files by issuing the command below:

deluser username  

To delete the user's home directory after the user is deleted, issue the following command as root:

deluser --remove-home username