Change default sudo password timeout

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 the timestamp_timeout option).

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

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.


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

Tags:

Sudo