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