In this tutorial we’ll learn how to edit sudo file on Ubunto and Centos.
A special user, called root
, has “super-user” privileges. This is an administrative account without the restrictions that are present on normal users. Users can execute commands with “super-user” or “root” privileges in a number of different ways.
In this article, we will discuss how to correctly and securely obtain root
privileges, with a special focus on editing the /etc/sudoers
file.
Obtain Root Privileges
Log In As Root
The simplest and most straight forward method of obtaining root
privileges is simply to log into your server as the root
user from the onset.
If you are logging in through SSH, specify the root
user prior to the IP address or domain name in your SSH connection string:
ssh root@server_domain_or_IP
Use “su” to Become Root
We can do this by invoking the su
command, which stands for “substitute user”. To gain root
privileges, simply type:
su
When you have finished the tasks which require root
privileges, return to your normal shell by typing:
exit
Use “sudo” to Execute Commands as Root
The final, and most complex, way of obtaining root
privileges that we will discuss is with the sudo
command.
The sudo
command allows you to execute one-off commands with root
privileges, without the need to spawn a new shell. It is executed like this:
sudo command_to_execute
Unlike su
, the sudo
command will request the password of the user calling the command, not the root
password.