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.