How to Keep ‘sudo’ Password Timeout Session Longer in Linux

In recent articles, we’ve showed you 10 Useful Sudoers Configurations in Linux and Let Sudo Insult You When You Enter Incorrect Password, and in this article, we discovered a another sudo tip that will help you to make sudo password sessions (timeout) longer or shorter in Ubuntu Linux.

In Ubuntu and its derivatives such as Linux Mint or any other Ubuntu-based distro, when you execute a sudo command, it will prompt you to enter administrative password.

After you execute sudo command first time, the password will last for 15 minutes by default, so you don’t need to type password for every sudo command.

If, somehow you feel that the 15 minutes too long or short for some reason, you can change it with a easy tweak in sudoers file.

To set the sudo password timeout value, use the passwd_timeout parameter. First open the /etc/sudoers file with super user privileges using sudo and visudo commands like so:

$ sudo visudo 

Then add the following defaults entry, it implies that the sudo password prompt will time out after 20 minutes once sudo is invoked by a user.

Defaults        env_reset,timestamp_timeout=20

Note: You can set whatever time you want in minutes and make sure to wait before it times out. You can also set time to 0 if you want a password prompt for every sudo command you execute, or disable password prompt forever by setting the value -1.

The screen shot below show the defaults parameters I have set in my /ec/sudoers file.

Change sudo Password Timeout
Change sudo Password Timeout

Save the file by pressing [Ctrl + O] and exit using [Ctrl + X]. Afterwards test if the setting is working by running a command with sudo and wait for 2 minutes to see if the password prompt will time out.

In this post, we explained how to set the number of minutes before the sudo password prompt times out, remember to share your thoughts concerning this article or perhaps other useful sudeors configurations for system administrators out there via the feedback section below.

If this article helped, with someone on your team.

TecMint Weekly Newsletter
Get the Learn Linux 7 Days Crash Course free when you join 34,000+ Linux professionals reading every Thursday.
Check your email for a magic link to get started.
Something went wrong. Please try again.
TecMint has been free for 14 years. Help keep it that way.
Google AI Overviews and tools like ChatGPT have cut into search traffic for independent tech sites like TecMint. Running this site costs over $2,000 every month for hosting, infrastructure, and paying authors to keep the content accurate and tested.

If this article helped you solve a problem, consider buying a coffee. It helps keep TecMint free, supports the authors, and keeps the project going.
☕ Buy Me a Coffee
Aaron Kili
Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Each tutorial at TecMint is created by a team of experienced Linux system administrators so that it meets our high-quality standards.

1 Comment

Leave a Reply
  1. In case you’re a weirdo vim user (like me) before executing the visudo command, reset the editor for visudo, entering this command in your terminal and following the prompts.

    $ sudo update-alternatives --config editor
    
    Reply

Got Something to Say? Join the Discussion...

Thank you for taking the time to share your thoughts with us. We appreciate your decision to leave a comment and value your contribution to the discussion. It's important to note that we moderate all comments in accordance with our comment policy to ensure a respectful and constructive conversation.

Rest assured that your email address will remain private and will not be published or shared with anyone. We prioritize the privacy and security of our users.

Free Course
Get a free Linux course before you go.
Subscribe to TecMint Weekly and get the Learn Linux 7 Days Crash Course free. Read by 34,000+ Linux professionals every Thursday.
Something went wrong. Please try again.
Check your email for a magic link to get started.