The sudo program allows a user to start a program with the credentials of another user. Before this works, the system administrator has to set up the /etc/sudoers file. This can be useful to delegate administrative tasks to another user (without giving the root password). The screenshot below shows the usage of sudo.

User ‘rd’ received the right to run useradd with the credentials of root. This allows ‘rd’ to create new users on the system without becoming root and without knowing the root password.

#/usr/sbin/useradd -m paul

First the command fails for user rd.

But with sudo it works.

su – $username

By default, the su command maintains the same shell environment. To become another user and also get the target user’s environment, issue the su – command followed by the target username.

#su - john


Visudo edits the sudoers file in a safe fashion. Visudo locks the sudoers file against multiple simultaneous edits, provides basic sanity checks, and checks for parse errors. Check the man page of visudo before playing with the /etc/sudoers file.

sudo su –

On some Linux systems like Ubuntu and Xubuntu, the root user does not have a password set. This means that it is not possible to login as root (extra security). To perform tasks as root, the first user is given all sudo rights via the /etc/sudoers. In fact all users that are members of the admin group can use sudo to run all commands as root.

#sudo grep rd /etc/sudoers

The end result of this is that the user can type sudo su – and become root without having to enter the root password. The sudo command does require you to enter your own password. Thus the password prompt in the screenshot below is for sudo, not for su.

#sudo su -

The following two tabs change content below.
Ruwantha Nissanka is a Professional Cyber Security Engineer from Sri lanka with having a demonstrated history of providing cyber security services for multiple organizations in Sri Lanka. He is a positive person who wants to believe the best in others and he likes to help, encourage people and make them feel good.