What are sudo commands? On common occasions, most users in a?Linux based VPS do not have root access when there are times you need a higher privilege to access within the VPS. Sudo commands allow sudoer, who isn¡¯t a root user, to access a file or system, in the situation when you need to be either a root user or a user with higher privileges. By default, root users don¡¯t need the sudo command.
Understanding Sudo
To understand how sudo works, access your VPS server with SSH as a non-root user. As a non-root user, you won¡¯t be able to add users to the Linux VPS usually. However, this can be allowed using the sudo command such as the one shown in the command line below.
sudo useradd <username>
Replace ¡°<username>¡± with the user¡¯s name of your preference. This is how non-root users are able to get higher privileges in a Linux VPS. A permission denied output will be revealed to users who don¡¯t use the sudo command without root access.
Sudoers File Syntax
The sudoers file is located at the directory ¡°/etc/sudoers¡±. To open the file, use any text editor of your preference. The following command uses the nano text editor to open the sudoers file.
nano /etc/sudoers
In the text file, you should be able to see the users¡¯ privileges specifications. The following line will explain what does the line means and how to understand them. There should be a line similar to the following.
root ALL=(ALL:ALL) ALL %admin ALL=(ALL) ALL %sudo ALL=(ALL:ALL) ALL
The following shows that all root users, admins, and sudoers have all privileges to run any command on the system. To break down what it means, For the ¡°%¡± symbol in front of admin and sudo specifies the group of users in the respective category.
We will break ¡°root ALL= (ALL:ALL) ALL¡± into a total of 5 fields.
- root – The 1st field of the syntax and it indicates the user type which the rule later will apply to it.
- 1st “ALL”?– The 2nd field of the syntax and it indicates the rules apply to all of the hosts.
- 2nd “ALL”?– The 3rd field of the syntax and it indicates the host can run commands as all users.
- 3rd “ALL”?– The 4th field of the syntax and it indicates the host can run commands as all the groups.
- 4th “ALL” – The 5th field of the syntax and it indicates the rules apply to all commands.