You should also be able to do this (at least you can on Linux, it may be different on OSX) by setting the timestamp_timeout
to 0 in /etc/sudoers
. This is the time for which the password is remembered . On most Linux distributions, the default is set at 15 minutes. Setting it to 0
means that sudo
will prompt for a password every time it is run. To change it do the following:
Run sudo visudo
, this will open a vim
session allowing you to edit /etc/sudoers
.
Hit i to enter INSERT mode
Add this line
Defaults timestamp_timeout=0
Hit Esc to exit INSERT mode
Hit :wqEnter to save the file and exit.
Now, sudo
will always ask for a password, even if you have just given it one. If you think this is too strict, you can use a higher value, say 5
for five minutes or 0.5
for 30 seconds.
Exactly what I had in mind, thanks. Sorry it took me 3+ years to select the best answer :/ – monstasaurous – 2016-10-27T23:48:19.533
2I think
exit
to quit the terminal works for me on Linux, in the sense that sudo's cache is restricted to a single pseudo-tty, and the cache is somehow cleared when the pty is closed. – sourcejedi – 2013-02-19T21:35:54.9902@sourcejedi, it works, but it also has the side effect of quitting the terminal! Which I think is more than the OP was asking for. – Andrew Ferrier – 2013-02-19T21:37:07.650