Disable Sudo Password Prompt or Extend Timeout in Linux

Last updated on | 2 replies

Every time you issue a sudo command, Linux asks for your user password after a certain inactivity timeout, usually 5 minutes. This is the recommended behaviour to prevent unauthorised commands being run by someone or a malicious script in your absence. However, this requirement can be disabled per session or permanently, or you can extend the inactivity timeout.

Disable Per Session

This command below will prompt you for your sudo password once and never again until you log out and in again.

sudo -i

Extend Inactivity Timeout

The default inactivity timeout is usually 5 minutes before Linux will prompt for your sudo password again. You can extend this timeout by editing the sudoers file. The visudo command opens an editor and points it to the sudoers file (Ubuntu defaults to nano, other systems use Vi)

sudo visudo

Look for the line Defaults env_reset

Add to the end of it ,timestamp_timeout=60  (where 60 is the amount of minutes).

/etc/sudoers.tmp
Defaults env_reset,timestamp_timeout=60

Save changes and close (In nano, press CTRL + X and then press y and ENTER)

Disable Permanently

You can disable this sudo password prompt permanently using the sudoers file. However, it is not recommended that you do this for security reasons. Unauthorised commands could be run by someone or a malicious script in your absence. If you understand the implications, run visudo to open the sudoers file (Ubuntu defaults to nano, other systems use Vi)

sudo visudo

At the bottom of the file, paste in the following, replacing username with your own.

/etc/sudoers.tmp
username ALL=(ALL) NOPASSWD:ALL

Save changes and close (In nano, press CTRL + X and then press y and ENTER)

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

2 replies

Leave a reply

Your email address will not be published. Required fields are marked *