Use Sudo Privileges Without Entering Password

When working on your server, you will often need to escalate to administrator privileges, either to install programs or edit system files which are owned by root. These are tasks which are normally reserved for the root account only, but a normal user account can also be given the ability to do these tasks, by being added to the sudo group. ‘Sudo’ is the ability for a user to perform admin tasks. It also gives a system admin to administer control over just what the user can and cannot do. They can do all admin tasks, or only those tasks specified the system admin. For your home server, you will most likely be giving your user privileges to do all tasks.

To have sudo privileges, the user must be part of the sudo group. To check if you are part of the sudo group, run the groups command. In the screenshot below, you can see that sudo is one of the groups listed for user jupiter.

Using Sudo

When you go to do an admin task, i.e. sudo ls /root, you will be prompted to enter your normal user password. This can become inconvenient and a hassle if you have to do it repeatedly in a short time. To enable sudo without having to enter the password every time, you need to add the user to the sudoers file. The sudoers file, saved at /etc/sudoers, is a configuration file for the sudo command on the system.

To avoid corrupting your system, the sudoers file must only be edited using the visudo command. Never try to edit the file directly using another text editor, such as nano or vi.

To add a user to the sudoers file, run the command ‘sudo visudo’. Scroll to the bottom and enter the following for your user:

Once you log out and log back in again you should be able to run sudo commands without being prompted for your password.

Leave a comment