3

On Debian, sudo asks for user password by default. On Raspberry Pi OS, it doesn't.

How to configure sudo to ask for user password?

1
  • Edit /etc/sudoers.d/010-pi-nopasswd. The no password setting is in there.
    – Dougie
    Commented Feb 24, 2021 at 17:39

3 Answers 3

4

Edit /etc/sudoers.d/010_pi-nopasswd and remove NOPASSWD word from it.

Be careful if you edit it using a regular text editor: if you make a mistake, save the file and quit, you will end up with a broken sudo and no way to edit the configuration again (which requires sudo).

Either don't close the editor until you have tested the new configuration, or have a root session open in another terminal just in case, or use visudo to edit the file (visudo refuses to save files if there are syntax errors). You can also set a password for root which lets you login as root and recover your system.

3
  • Thanks! Is it OK to delete this file?
    – sunknudsen
    Commented Feb 22, 2021 at 12:21
  • I ran sudo rm /etc/sudoers.d/010_* and so far everything works fine.
    – sunknudsen
    Commented Feb 22, 2021 at 12:26
  • 1
    @sunknudsen Yeah, the pi user also belongs to the sudo group, so it will fall back to the group policy if you remove that file. My only fear is that apt may recreate that file again during an upgrade. If you modify it, apt will not touch it without asking you. Commented Feb 22, 2021 at 13:01
0

Apparently you can just add . to the filename of /etc/sudoers.d/010_pi-nopasswd to disable the NOPASSWD rule. This is stated in the README in the same directory with recent versions of Pi OS. It seems to work for me.

Example:

cd /etc/sudoers.d
sudo mv 010_pi-nopasswd .010_pi-nopasswd
0

Another possibly even cleaner way is to go ahead and edit the file, but keep the change simple, just put a # sign at the start of the line with the user you want to require a password to comment it out. This way you can easily revert or even have users that can use passwordless along with users that cannot and if anything is hardcoded to expect that file to be there it will still be.

1
  • this is not an answer to the question ... it belongs in the comment section ... please delete it
    – jsotola
    Commented May 18 at 18:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.