Ubuntu – Sudo is not asking for password on Ubuntu 16.04

passwordpermissionssudousers

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

Best Answer

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?

Related Question