Disable Sudo Password Prompt or Extend Timeout in Linux

Last updated on

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 in the comments if this helped. Follow me @DevAnswers or read more.

1 Star2 Stars3 Stars4 Stars5 Stars

Feedback

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

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces