13

I find that if I execute something using sudo that then if I execute something else soon after also using sudo, that it does not prompt me for my password, and although this can be inconvenient in some situations, it is a security risk in others, and a hassle to keep on coming back and executing the command to make it prompt your for the password on the next go. So I was wondering if and how I could get it to prompt me every time, or for it to at least only remember my password for a very short amount of time?

1
  • In the opposite situation, if you work in a low-risk environment, constant prompting is incredibly irritating. Thanks for your question because the solution is essentially the same: change the timeout.
    – Suncat2000
    Sep 9, 2023 at 18:56

2 Answers 2

18

Open Terminal and type:

sudo visudo

Then scroll down to the line that reads:

Defaults        env_reset

And change it to:

Defaults        env_reset,timestamp_timeout=0

You can change 0 to any values (time in minutes). Setting it to 0 will ask for your password every time and -1 will make it never ask. The default is 15 according to man sudo 8, but some manuals say the default is 5. Have a look at the RootSudoTimeout wiki for more information.

Press CTRL + X to finish editing, Y to save changes, and ENTER to exit.

4
  • 1
    What's the default timeout period?
    – LDC3
    Jun 13, 2015 at 18:08
  • Yes, sorry about that. 15 mins according to man sudo 8, but some manual says 5
    – Ron
    Jun 13, 2015 at 18:17
  • Believe the manual you have on your system. Different distributions can chose their own defaults.
    – terdon
    Jun 13, 2015 at 21:04
  • 1
    Believe the source, rather than the manual.
    – waltinator
    Jun 13, 2015 at 21:15
0

From Terminal run:

echo "testuser1  ALL=(ALL)   PASSWD: ALL" >> /etc/sudoers

Or:

visudo -f /etc/sudoers

Add the following line at the bottom of the file:

testuser1 ALL=(ALL)   PASSWD: ALL

You must log in to answer this question.