When I run sudo and enter my password, a subsequent invocation of sudo within a few minutes will not need the password to be re-entered.
How can I change the default timeout to require the password again?
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
man sudoers says:
Once a user has been authenticated, […] the user may then use sudo without a password for a short period of time (5 minutes unless
overridden by thetimestamp_timeoutoption).
To change the timeout, run, sudo visudo and add the line:
Defaults timestamp_timeout=30
where 30 is the new timeout in minutes.
To always require a password, set to 0. To set an infinite timeout, set the value to be negative.
To totally disable the prompt for a password for user ravi:
Defaults:ravi !authenticate
Method 2
sudo visudo is to modify the default configuration file directly, but in the file has suggestion below
Please consider adding local content in /etc/sudoers.d/ instead of directly modifying this file.
So, better way is
cd /etc/sudoers.d
sudo visudo -f user_name
Add the content
Defaults timestamp_timeout=(number)
(number) is the new timeout in minutes.
timestamp_timeout (man 5 sudoers)
Number of minutes that can elapse before sudo will ask for a passwd again. The timeout may include a fractional component if minute granularity is insufficient, for example 2.5. The default is 15. Set this to 0 to always prompt for a password. If set to a value less than 0 the user’s time stamp will not expire until the system is rebooted. This can be used to allow users to create or delete their own time stamps via “sudo -v” and “sudo -k” respectively.
Save the file by pressing Ctrl + O and press enter, and exit using Ctrl + X.
Method 3
You need to edit /etc/sudoers. For those who don’t use vi, you should edit this file (on some flavors of Linux) with a terminal command like this:
sudo EDITOR=gedit visudo
Then add or change timestamp_timeout:
# After authenticating, this is the amount of time after which # sudo will prompt for a password again in the same terminal Defaults timestamp_timeout=30
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0