Prevent sudo from prompting for password when running non-permitted command

From a quick read of sudo(8)

   -n          The -n (non-interactive) option prevents sudo from
               prompting the user for a password.  If a password is
               required for the command to run, sudo will display an error
               message and exit.

And for the doubters:

# grep jdoe /etc/sudoers
jdoe    ALL=(ALL) NOPASSWD: /bin/echo
#

Tested thusly:

% sudo echo allowed
allowed
% sudo -n ed             
sudo: a password is required
% sudo ed               

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

Password:

So an alias for sudo for these folks would likely do the trick, to prevent the password prompt. Now why this requires custom compiling sudo, I don't know, I just read the manual.


One thing that worked for me, (Sudo version 1.8.17p1), but satisfies only part of your problem, is to set the number of password tries to 0.

Defaults:%mygroup passwd_tries = 0

This makes sudo exit with code 1 when any command requiring a password is tried. However, it doesn't produce any sort of error message.


You can not.

There is no way to tell who you are until you have authenticated, and, by default you can not authenticate without a password.

You could change authentication to use USB keys, finger print scanners, voice auth, face recognition, or a bunch of other stuff, but the point is the same.

You can not authenticate, with out authenticating AND before you authenticate sudo has no business telling you what you can or can not run.

Tags:

Sudo