GICT knowledge base
How to Keep sudo Password Timeout Longer in Linux
Published
When you use Linux, the system asks for your password every 15 minutes when you use sudo commands. This can be very annoying during work. You can change this setting to make it longer.
What is sudo Password Timeout?
Linux has a security feature that forgets your password after 15 minutes. This means you have to type your password again and again when doing admin work. While this keeps your computer safe, it can slow down your work.
Why Make Timeout Longer?
Making sudo timeout longer helps you in many ways. You do not need to type your password so many times. Your work goes faster when you do system tasks. You get less interruptions when running many commands.
How to Change Timeout Settings
Change the Main File
The best way is to edit the sudoers file. This change stays even after you restart your computer.
Type this command:
sudo visudo
Add this line:
Defaults env_resets, timestamp_timeout=60
Note: You can choose any number of minutes for your timeout setting. Make sure to use sudo commands before the time runs out. If you want the system to ask for a password every time you use sudo, set the time to 0. If you never want to enter your password again, set the value to -1. Remember that setting -1 removes all password protection and can be unsafe.
Change 60 to any number of minutes you want. Save the file and close it. The new setting works right away.
Set Different Time for Each User
You can give different timeout to different users on your computer.
Add this line:
Defaults:john timestamp_timeout=90
Change “john” to the real username. Change 90 to the minutes you want.
Set Time for Groups
You can also set timeout for groups of users.
Add this line:
Defaults:%admin timestamp_timeout=120
Change “admin” to your group name. Change 120 to minutes you want.
Refresh Current Session
If you want to refresh your current work session, use this:
sudo -v
This makes your sudo session fresh without running other commands.
Safety Things to Remember
Making timeout longer can create safety problems. If you leave your computer unlocked, other people can use it. Do not use long timeouts on shared computers. Be careful on computers that connect to the internet.
Think about safety before making changes. Home computers are different from office computers. Find the right balance between easy use and safety.
Advanced Settings
You can turn off password asking completely:
Defaults timestamp_timeout=-1
This is very dangerous. Most people should not do this.
Test Your Changes
After making changes, test them to make sure they work.
Run a sudo command and type your password. Wait for a few minutes. Run another sudo command. If it does not ask for a password, your change worked.
Common Problems
If changes do not work, check these things. Make sure you use visudo to edit the file. Check that you have admin rights on the computer. Remember that changes work only for new sessions.
If you make mistakes and lose sudo access, you might need help from someone else or use recovery mode.
Good Ways to Use
Start with small changes like 30 minutes. Watch how you use your computer. Write down what changes you made. Check your settings every few months.
Use different settings for different computers. Work computers need different settings than home computers.
Other Ways to Work Safely
If you need admin access often but want to stay safe, try these ideas:
- Use SSH keys for remote work.
- Make rules for commands you use often.
- Use programs like screen that keep sessions running.
- Write scripts that do many tasks together.
Conclusion
Making sudo timeout longer helps you work faster. But keeping your computer safe is most important. Start with small timeout changes. See what works best for your daily work.
Only make big changes when your computer is in a safe place. Always remember that a longer timeout means more risk. With good settings, you can work better and keep your computer safe.
Use these methods to set up sudo timeout that help your work. Keep your system protected while making your daily tasks easier and faster.
This change can make using Linux much better. Try it and see how much time you save during your work.
Related guides
How to Restrict an SSH Key to One Command
Restrict an SSH key to one command with authorized_keys options. Protect the command and check that unwanted shell and forwarding access are denied.
Linux and CommandsSelf-Hosted Video Processing With FFmpeg: A Practical Guide
Learn how to self-host video processing on a VPS using FFmpeg, with practical commands for conversion, compression, thumbnails, and automated workflows.
Linux and CommandsHow to use nohup: Commands in Linux That Survive Terminal Closes
Keep commands running after you close the terminal. nohup examples with wget, Python, rsync, and Docker on any VPS.
Linux and CommandsHow to Fix “Too Many Open Files” Error on Linux Servers
Learn how to fix the "Too Many Open Files" error on Linux servers by understanding file descriptors, adjusting limits, and diagnosing leaks effectively.
