Guides 11792 Published by

This guide walks you through adjusting how long sudo keeps your authentication so you won’t be prompted every few minutes during admin tasks. It explains that you can check the current setting with sudo visudo -c, then safely edit /etc/sudoers using visudo to add or change a line like Defaults timestamp_timeout=30, zero for no caching, or –1 for never expire. After making the change you must run sudo -k to invalidate the old timestamp and test by running a privileged command, waiting the set number of minutes, and confirming that sudo still works without re‑entering your password. The author even shares a real‑world example where bumping the timeout from five to twenty minutes after installing a graphics driver eliminated annoying password prompts every time the screen woke up.



How to Change the Sudo Password Time

If you’re tired of entering your password every few minutes while doing admin work on Linux, you can tweak how long sudo remembers that you’re authenticated. The timeout lives in /etc/sudoers, and a quick edit will let you keep working longer without the nag.

Why You Might Want to Extend or Shorten It

I’ve seen people hit “Enter your password” every 5 minutes on a fresh install, which is fine when you’re just testing. But if you’re running a build script that touches privileged files every 30 seconds, you’ll be frustrated. On the other hand, some folks prefer the shorter window for security reasons. Adjusting timestamp_timeout gives you control.

Check What’s Currently Set

1. Open a terminal and run:

   sudo visudo -c

2. The command will parse /etc/sudoers. Look for a line that starts with Defaults timestamp_timeout=. If it’s missing, the default is 15 minutes.

Safely Edit the File

1. Run sudo visudo to edit the file in a safe editor.

2. Find or add a line like:

   Defaults timestamp_timeout=30

3. Replace 30 with whatever number of minutes you prefer. Set it to 0 if you want no caching at all, or -1 for “never expire” (useful on a personal workstation but risky elsewhere).

The visudo command checks for syntax errors before saving, so you won’t break sudo by accident. A typo could lock you out of privileged commands.

Reset the Current Timestamp

After changing the timeout, old sessions still use the previous timer until they expire. To start fresh:

sudo -k   # invalidates the current timestamp immediately

Now the next sudo command will prompt for your password again, and from that point forward it will respect the new setting.

Quick Test

1. Run a privileged command, e.g., sudo whoami.

2. Note the time of the password prompt.

3. Wait the number of minutes you set (timestamp_timeout).

4. Run another privileged command without entering a password again. If it still asks, double‑check your edits.

A Real‑world Observation

After installing a new graphics driver on my laptop, I noticed that every time the screen would sleep and wake, sudo forced me to re‑enter my password. By bumping the timeout from 5 to 20 minutes, those sleepy cycles no longer interrupted my workflow. If you’re in the same boat, give it a try.

That’s all there is to it: tweak one line, restart your session or invalidate the timestamp, and enjoy a smoother sudo experience.