Commands.page Logo

How to Extend Sudo Timeout Period in Ubuntu Linux

This article provides a step-by-step method to change the sudo password caching duration on Ubuntu systems. You will learn how to safely edit the configuration file to increase the timeout limit from the default setting. Follow the instructions below to customize this security parameter effectively.

By default, Ubuntu remembers your sudo password for 15 minutes. After this period expires, you must re-enter your password to execute privileged commands. To change this duration, you need to modify the sudoers file using the visudo command, which prevents syntax errors that could lock you out of sudo access.

Open your terminal and run the following command to edit the sudoers file safely:

sudo visudo

This opens the configuration file in the default text editor. Look for a line that starts with Defaults. If you do not see a specific timeout setting, you can add a new line anywhere within the file, preferably near the other Defaults entries. Add the following line to set the timeout to 30 minutes:

Defaults timestamp_timeout=30

Replace 30 with the number of minutes you prefer. Setting the value to 0 will require a password for every sudo command, while a higher number extends the cache duration.

Once you have added or modified the line, save the file and exit the editor. If you are using Nano, press Ctrl + O to save and Ctrl + X to exit. If you are using Vi or Vim, type :wq and press Enter. The system will check the file for syntax errors before applying the changes.

To verify the new setting, run a sudo command such as sudo ls. Enter your password when prompted. Wait for a period shorter than your new timeout limit and run the command again. You should not be asked for a password. Wait until after the timeout period expires and run it once more to confirm that the password prompt returns as expected.