Sudo is not asking for password on Ubuntu 16.04

5,337

You had a NOPASSWD rule applied to your user in some file in /etc/sudoers.d. Use sudo grep NOPASSWD /etc/sudoers.d -R to find out which.

Your /etc/sudoers is not the default, however. The default sudoers can be obtained by looking at the sudo package:

$ apt-get download sudo
Get:1 http://mirror.cse.iitk.ac.in/ubuntu xenial-updates/main amd64 sudo amd64 1.8.16-0ubuntu1.1 [389 kB]
Fetched 389 kB in 0s (4,750 kB/s)
$ dpkg-deb --fsys-tarfile sudo*.deb | tar x ./etc/sudoers
$ cat etc/sudoers 
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults    env_reset
Defaults    mail_badpass
Defaults    secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL:ALL) ALL

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# See sudoers(5) for more information on "#include" directives:

#includedir /etc/sudoers.d

This is rather different from what you have. Restore /etc/sudoers to the default.

For excluding specific commands from requiring a password, see How do I run specific sudo commands without a password?

Share:
5,337

Related videos on Youtube

bha159
Author by

bha159

Discovered Ubuntu after using computer for 11 years. Instantly fell in love with it. Still lot to learn :)

Updated on September 18, 2022

Comments

  • bha159
    bha159 about 1 year

    Ever since I update to 16.04 I notice whenever I use any sudo command the terminal does not ask me the password before executing the command,The command is directly executed.I am the admin and I have no other user accounts.

    I have seen sudo does not ask for password and my /etc/sudoers is exactly like given in answer but still when using sudo command, terminal does not prompt a password instead execute the command.

    I would like to know in detail how can /etc/sudoers can be modified for

    • Making any particular user account(including admin) to be prompted or not prompted for password when using sudo command.

    • How to exclude any particular command to be excluded from prompting password when using sudo for any user account(including admin).

    Here is my sudoers file

    # /etc/sudoers
    #
    # This file MUST be edited with the 'visudo' command as root.
    #
    # Please consider adding local content in /etc/sudoers.d/ instead of
    # directly modifying this file.
    #
    # See the man page for details on how to write a sudoers file.
    #
    
    Defaults    env_reset,timestamp_timeout=0
    
    # Uncomment to allow members of group sudo to not need a password
    # %sudo ALL=NOPASSWD: ALL
    
    # Host alias specification
    
    # User alias specification
    
    # Cmnd alias specification
    
    # User privilege specification root ALL=(ALL) ALL
    
    # Members of the admin group may gain root privileges %admin ALL=(ALL) ALL
    
    # See sudoers(5) for more information on "#include" directives:
    
    #includedir /etc/sudoers.d
    

    Output of sudo -l

    Matching Defaults entries for bharat on ratcoder:
        env_reset, timestamp_timeout=0
    
    User bharat may run the following commands on ratcoder:
        (ALL) NOPASSWD: ALL
    
    • muru
      muru over 7 years
      Please add the output of sudo -l.
    • bha159
      bha159 over 7 years
      @muru Please see I have added it in the question itself.
    • muru
      muru over 7 years
      some file in /etc/sudoers.d has the NOPASSWD rule. Find and delete it
    • bha159
      bha159 over 7 years
      @muru how can I do it? There are 3 files in '/etc/sudoers.d' and they don't open.
    • muru
      muru over 7 years
      sudo grep NOPASSWD /etc/sudoers.d -R
    • bha159
      bha159 over 7 years
      @muru Now I am getting error bharat is not in the sudoers file. This incident will be reported.
    • muru
      muru over 7 years
      Sigh.. You didn't restore the default rule before doing that? Run pkexec visudo and add %sudo ALL=(ALL) ALL before the includedir line.
    • bha159
      bha159 over 7 years
      @muru Thanks it helped. Would you please write the answer so that I can accept it and move on. I don't like unanswered questions. And if possible please write how can particular can be excluded so that they don't require password using sudo. Again thanks a lot.
  • bha159
    bha159 over 7 years
    Editing with this does not change anything still sudo does not prompt for password, and I would like to know how to exclude(or include) specific command or user.
  • Sudhir Singh Khanger
    Sudhir Singh Khanger over 3 years
    1. Was setting a root password and ubuntu user password a useless thing to do? 2. Is this safe that a user (ubuntu) doesn't require root password?