Change sudo Timeout: How to Adjust the Prompt Delay

Customizing the Sudo Password Timeout
When executing commands with elevated privileges using sudo, you are typically asked to authenticate with your password. A convenient feature exists where subsequent sudo commands, executed within a short timeframe, may not require re-entry of your password.
The duration of this password-less grace period can be adjusted by modifying a sudo configuration setting. This allows you to balance security and convenience.
NOTE: When instructed to type text in this guide, do not include the surrounding quotation marks, unless explicitly stated.
Modifying the Sudoers File
We will modify the "/etc/sudoers" file to customize the timeout period. Begin by opening a Terminal window. Press Ctrl + Alt + T to initiate this process.
Then, enter the following command at the prompt and press Enter:
sudo visudo
You will be prompted to enter your password. Provide it and press Enter.

The file will open within the Terminal using the Nano text editor. Utilize the arrow keys to navigate to the end of this line:
Defaults env_reset
IMPORTANT: Always use the visudo command to edit the sudoers file. Avoid using standard text editors. Incorrect syntax in this file can render your system unable to obtain root privileges.
visudo validates the file's syntax upon saving, preventing configuration errors that could block sudo operations and potentially lock you out of root access.
While Linux traditionally defaults to vi, Ubuntu employs Nano. If you prefer vi as your default editor in Ubuntu, consult our dedicated article on the subject.

Setting the Timestamp Timeout
Modify the line by appending ", timestamp_timeout=x" to its end.
Defaults env_reset, timestamp_timeout=x
Substitute "x" with the desired number of minutes for the sudo password grace period within the same Terminal session.
Entering "-1" for "x" disables the password prompt entirely, which is generally not recommended. A value of "0" for "x" will require a password for each sudo command invocation.

Saving and Exiting
After making the change, press Ctrl + X. You will be prompted to save your modifications; respond with "y".

You will be asked to confirm the File Name to Write. Press Enter to accept the default filename.

You will return to the command prompt. To close the Terminal window, type "exit" and press Enter. Alternatively, click the X button in the upper-left corner.

Clearing the Password Cache
You can also manually clear the sudo password cache by executing the following command at the prompt and pressing Enter:
sudo --k
This will force a password prompt for the next sudo command, even if the configured grace period has not elapsed.