To increase the sudo timeout in Linux, you need to adjust the timestamp_timeout setting. This setting controls the amount of time, in minutes, that a user’s sudo authentication remains valid before requiring re-authentication.
Here’s how you can increase the sudo timeout:
Edit the Sudoers File
Open the sudoers file for editing using visudo to ensure that the syntax is correct and to prevent simultaneous edits by multiple users:
sudo visudoFind the Defaults section and add or modify the timestamp_timeout setting. For example, to set the timeout to 30 minutes: Defaults timestamp_timeout=30
- To make the sudo session last indefinitely, set the timeout to -1:
Defaults timestamp_timeout=-1Save and exit the file. In visudo, this is usually done by pressing Ctrl + X, then Y to confirm, and Enter to save.
Set Sudo Timeout for a Specific User
If you want to set the sudo timeout for a specific user, you can add a line in the sudoers file specific to that user:
Defaults:username timestamp_timeout=30Replace username with the actual username.
Example Sudoers File Entry
Here is an example of how the relevant section in the sudoers file might look after the change:
# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL
# Set the sudo timeout to 30 minutes
Defaults timestamp_timeout=30Verify the Changes
To verify the changes, you can run a command with sudo, wait for the specified timeout period, and then run another command with sudo to see if it asks for the password again.
Summary
By editing the sudoers file and adjusting the timestamp_timeout setting, you can control how long a user’s sudo authentication remains valid before requiring re-authentication.

