The sudo
command in Linux is your gateway to administrative powers—installing packages, modifying system files, and much more. By default, Linux will prompt you to re-enter your password after a few minutes of inactivity to ensure security. Depending on your workflow or comfort level, you may want to tailor these password prompts to better suit your needs. This guide covers three approaches: disabling the prompt for a single session, extending the inactivity timeout, and removing the prompt entirely.
Why Does Sudo Prompt for a Password?
The primary purpose of prompting for a password is to protect your system from unauthorized usage. If you walk away from your computer, or if someone gains remote access to your session, the sudo prompt reduces the chance of them running privileged commands. However, you might find the repeated requests inconvenient, especially if you are actively working on system-level tasks.
Disable Sudo Password Prompt for the Current Session
If you don’t want to be bothered by repeated password prompts during a single session, you can open a root shell. Once you have authenticated, you will not be prompted for your sudo password again until you close the shell or log out.
sudo -i
After you run this command and type your password once, you can execute any administrative commands without additional prompts—until you exit from the root shell.
Extend the Sudo Inactivity Timeout
By default, many distributions keep a sudo session valid for around 5 minutes. If you find this duration too short (or too long), you can configure a custom timeout. Be mindful: setting a very long timeout can leave your system more vulnerable if you walk away.
First, open the sudoers
file using the secure visudo
command. This ensures your changes are validated before saving:
sudo visudo
Within the file, look for a line similar to Defaults env_reset
(it may appear multiple times). Append timestamp_timeout
to set your new duration in minutes. For instance, to extend it to 30 minutes, you can use:
Defaults env_reset,timestamp_timeout=30
Save and exit (press CTRL
+ X
, press Y
, then press ENTER
)
Next time you run sudo
, your session will remain active for 30 minutes of inactivity before requiring another password entry.
Disable the Sudo Password Prompt Permanently
Warning: Skipping sudo prompts altogether can be risky. Anyone or anything that gains access to your account can execute system-level commands without a password. Proceed only if you fully understand the implications.
Again, open the sudoers
file using visudo
. Then add a line at the bottom like so, but replace your_username
with your actual username:
your_username ALL=(ALL) NOPASSWD:ALL
Save and exit (press CTRL
+ X
, press Y
, then press ENTER
)
From that point onward, you won’t be asked for a password when using sudo
. Only do this if your environment is secure and you understand the consequences of removing this safeguard.
Conclusion
Mastering your sudo
configuration can streamline your workflow without sacrificing overall security—if you make informed decisions. You can disable prompts for a single session while you tinker away on administrative tasks, extend the inactivity timeout for a more comfortable cadence, or remove them entirely if your circumstances allow. When adjusting these settings, always remember that convenience should never overshadow security.
Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.
That 5-minute timeout is way too short!
Thanks so much for the “sudo -i”
Simply perfect. Thank you!?