How often is the password asked for sudo commands? Where can I set it up?

I execute quite a lot of sudo commands.

I noticed that if I execute one and then another one within few minutes, the 2nd time I don't get the message:

[sudo] password for my_username:

but I do get it when there is more time between the execution of the two commands.

What's the period of time in which the message is not appearing? How can we check it / update it?


The default timeout of sudo is 15 minutes; that is, sudo will remember your password for 15 minutes by default.

You can modify this default timeout by adding a string in the file /etc/sudoers. However, you don't modify the file directly, but instead you use the command sudo visudo.

So, type sudo visudo in a terminal. This will open up the (actually, a temporary) file for us to edit, using your preferred editor.

Note: if you are using visudo for the first time, you should be asked which editor you would like to use, so choose your editor. There's no "better" editor, but I prefer nano. If you've already used visudo and chose an editor before, but you want to use another editor for the time being, you can do sudo EDITOR=vi visudo to use vi, or change it to nano to use nano. If you want to permanently change your preferred editor, do sudo update-alternatives --config editor.

Look for this line:

Defaults    env_reset

And add timestamp_timeout=X (with a comma) at the end of it, where X is the time you want to set in minutes.

So your line should look like this, as an example:

Defaults    env_reset,timestamp_timeout=5

If you specify 0, you will always be asked the password. If you specify a negative value, the timeout will never expire.

Once done, save and exit.

Source: RootSudoTimeout


See this post here: http://ubuntuforums.org/showthread.php?p=116697#post116697

Edit /etc/sudoers file, use sudo visudo command for safety. Add timestamp_timeout=0 to the line starting Defaults to ask everytime, or positive X for X minute delay.


Not sure if this expires or not, but you could try

sudo su

It will ask you for the password and after that all commands are run as sudo.