Disable Sudo Password Prompt or Extend Timeout in Linux

Last updated on | 2 replies

When you run a command with sudo, Linux asks for your user password after a certain inactivity timeout, typically 5 minutes. This security feature prevents unauthorized commands from being executed by someone else or by a malicious script when you are away from your terminal. However, you can disable this prompt per session, extend the inactivity timeout, or even disable it permanently. Below, we’ll explore these options.

What is Sudo?

sudo stands for “superuser do.” It allows a permitted user to execute a command as the superuser or another user, as specified by the security policy. It is a powerful tool that can modify system configurations, install or remove software, and more.

Disable Sudo Password Prompt Per Session

To disable the password prompt for the current session, run the following command. After entering your password once, you won’t be asked again until you log out.

sudo -i

Extend Sudo Inactivity Timeout

The default inactivity timeout is usually 5 minutes before Linux prompts you for your sudo password again. You can extend this timeout by editing the sudoers file. The visudo command safely opens this file in your default text editor (Ubuntu uses nano by default, while other systems might use vi).

sudo visudo

Within the sudoers file, look for the line: Defaults env_reset

Add the following to the end of this line: timestamp_timeout=60 (where 60 is the number of minutes you want to set).

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

Save and exit (press CTRL + X, press Y and then press ENTER)

Disable Sudo Password Prompt Permanently

Disabling the sudo password prompt permanently is not recommended for security reasons. Unauthorized commands could be run by someone or a malicious script in your absence. If you understand the risks and still wish to proceed, open the sudoers file using the visudo command.

sudo visudo

At the bottom of the file, add the following line, replacing username with your own username.

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

Save and exit (press CTRL + X, press Y and then press ENTER)

Conclusion

In summary, managing the sudo password prompt can be tailored to your specific needs, whether it’s for a single session, extending the inactivity timeout, or even disabling it permanently. While these adjustments can improve convenience, it’s important to balance ease of use with security considerations. Always be mindful of the potential risks associated with disabling security features, and make informed decisions that best suit your working environment.

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 *