DEV Community

loading...
Cover image for Set the Sudo session timer

Set the Sudo session timer

rich1n profile image Richard Rodrigues ・2 min read

Limiting the Sudo session

By default, the console timer have 5 minutes (some distros have a 15 minute block time). This mean that each time you execute the ""sudo command"", you can use it without typing the password, but, only in that 5 minutes time block; after that, you need to enter your password again.

This protection is very useful; you don't want nobody in your system while you're absence. But if you're working all the time in the Linux Terminal, you'll need this session be longer. In this article you'll learn how to set a time limit for your "superuser do" session.

Remember: this modification could be a risk for you system integrity, if you work with other people and you walk away from your workspace, don't do this or just kill session.

Setup the Sudoer File

You only need to add an order to the "sudoer" file (default sudo security policy plugin located at /etc/sudoer); open sudoers with visudo commando or just open the file for edit:

sudo visudo
Enter fullscreen mode Exit fullscreen mode

or

sudo nano /etc/sudoers
Enter fullscreen mode Exit fullscreen mode

Will show the following screen

Sudoer Screen

In default options we need to add this:

Defaults      timestamp_timeout=
Enter fullscreen mode Exit fullscreen mode

Adding the value «0», will disable the timer and the system always request a password.

Sudoer 0

The value works in minutes; if we want to delay the session to 20 minutes we've insert this:

Defaults      timestamp_timeout=20
Enter fullscreen mode Exit fullscreen mode

Sudoer 20

You can add the value in the same line at default propierty(separating value with a comma (,):

Sudoer 15

Just save the setting and close the editor.

Another Sudo Options

Finishing sudo session just type:

sudo -k
Enter fullscreen mode Exit fullscreen mode

Kill sudo

Another Sudo Options

You can keep the sudo session opened (at least you close the terminal or typing exit):

sudo -s
Enter fullscreen mode Exit fullscreen mode
sudo su
Enter fullscreen mode Exit fullscreen mode

Sudo Su

You´ll be in the superuser session without typing sudo command.

Discussion (0)

pic
Editor guide