Tired of having to provide a password to use sudo on Linux?

Justin Cartwright
2 min readAug 11, 2020

--

I know I am…

Photo by Mike Szczepanski on Unsplash

Invariably when I log into one of my linux servers over an SSH terminal, I end up wanting to modify some files that require root permissions. So I insert the necessary sudo command at the front of the line and proceed. However, I tend to use randomized passwords and it’s always a pain to look them up.

For this brief note, I’m using an Ubuntu v18.04.4 linux server. If you want to check your operating system version in linux, just execute the following command:

cat /etc/os-release

You should see some output such as:

NAME="Ubuntu"
VERSION="18.04.4 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.4 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

Now whenever I am working with a new server, I setup a non-root user as best practice, which is why I end up getting prompted to enter a password whenever using sudo. For this example, let’s pretend our username is bobrobot. What we need to do is add a line into a file located at /etc/sudoers that allows bobrobot to execute sudo (i.e. superuser do) without being questioned.

Go ahead and choose your favorite text editor (e.g. emacs, vim, or nano) and open up this file:

sudo vim /etc/sudoers

You should see a comment near the bottom of this file that looks like

#includedir /etc/sudoers.d.

Directly below this line, go ahead and insert the following (using your username instead of bobrobot):

bobrobot ALL=(ALL) NOPASSWD:ALL

Save and exit the file. You may need to logout and back in before the changes come into effect. That’s it!

--

--

Justin Cartwright
Justin Cartwright

Written by Justin Cartwright

Principal Software Engineer @ Fennec Engineering, Runner, Caipirinha Maker.

No responses yet