Configure password (less) sudo in Ubuntu 16.04

Changing /etc/sudoers does not remove the password prompt for all sudo commands.

do Not change sudoers

Do not change sudoers if you want to use sudo with no password prompt on Ubuntu 14.04 and 16.04?

The line at the bottom of your sudoers file #includedir /etc/sudoers.d is not a comment. It is an include that overwrites your sudoers change.

How to End Sudo Password Prompts in Ubuntu

You can either add a file (with visudo) to the /etc/sudoers.d directory or you can append to an existing file.

All Amazon EC2 cloud instances come without password prompts for the first user. If this applies to you – appending to the /etc/sudoers.d/90-cloud-init-users file is an option. It pays though to start your own configuration.

Step 1 – Use visudo to create and edit

The visudo command opens up a new configuration file.

sudo visudo -f /etc/sudoers.d/custom-users

It is important

  1. to use visudo – it is safe with it and treacherous without
  2. that your filename has neither dots nor squigglies. So my-users.conf is a no-no!
  3. not to change sudoer (or sudoers.d) permissions – immediate lock out results

The visudo command presents you with an empty file.

Step 2 – Configure No sudo Password Prompts

Never used the vi editor? – It does not matter – you just type in a comment line and the sudo configuration line.

# This configuration will silence password prompts when sudo is used
# For documentation visit build business websites and search on sudoer

<<username>> ALL=(ALL) NOPASSWD:ALL

Now we need to save the file.

Step 3 – Save and Exit Visudo

Hold down the Ctrl-Key and press the letter x.

To confirm press shift and Y

Press Enter to agree to a temporary file. That’s it.

Step 4 – Verify no password prompts after sudo

It pays to start a new shell as the user specified – and test it with say sudo date

No password prompt! Well done – lights out and away you go.

3 comments

  • Hi,
    <> ALL=(ALL) NOPASSWD:ALL
    Iam using UBUNTU 16.04 on Beaglebone black board.This command is not working for me
    By editing sudoers file i checked by reboot the system..Then to run any command it again asking for password..
    Please help me how to resolve this issue
    Thanks.

    • Iakshmi Hi

      Try creating the new user this way (hands free). If user is called iakshmi then your script would be


      sudo adduser --disabled-password --gecos '' iakshmi
      sudo adduser iakshmi sudo
      sudo echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers

      Try this and let me know if it works!

    • I’ve also noticed that you put angular brackets in your command – your username is supposed to go there.

      Instead of
      <> ALL=(ALL) NOPASSWD:ALL

      please try
      iakshmi ALL=(ALL) NOPASSWD:ALL

Leave a Reply

Your email address will not be published. Required fields are marked *