How to Change Sudo Sessions Timeout Limit on Ubuntu Linux

|

|

This tutorial guides users on changing the default sudo sessions timeout limit on Ubuntu 18.04 and 16.04. By default, Ubuntu requires a password re-entry after 15 minutes of sudo sessions. To change the time limit, users can manually set timeout limits or globally alter the sudo timeout session by modifying the sudoers file.

This brief tutorial shows students and new users how to change | adjust the sudo sessions timeout limit on Ubuntu 18.04 | 16.04.

By default on Ubuntu, after 15 minutes of sudo sessions, you’ll have to reenter your password to continue using the sudo command tool. This can be frustrating in some cases, and if you find yourself in similar situations, follow the steps below to change how often sudo sessions terminate.

If you enter your password to run a sudo command out of the box, you can continue to run subsequent commands using the existing session for 15 minutes.

When the 15 minutes are out, you’ll be forced to reenter your password.

How to manually set Sudo Timeout Limits

Without modifying the Sudoers file, you can manually set when you want a sudo session to last by running a simple command. For example, if you want to use an existing sudo session forever until you terminate it, simply run the sudo command with an -s or the --shell option.

The -s option allows you to run the shell as the target user who is running it.

Example:

sudo -s

With that, you can continue to use an existing sudo session forever until you terminate it with an -k or the --reset-timestamp option:

Then -k option invalidates the timestamp file.

Example:

sudo -k

If you initiated a sudo session with the sudo -s option, the -k option will not terminate the sessions. You must exit to end that session.

Set Sudo Timeout Sessions Globally

If you want to extend or reduce this default timeout limit for the sudo session globally or system-wide, simply on the sudoers file and make the changes there.

Run the commands below to open the file.

sudo visudo

Then on the highlighted line, change how long you want sudo sessions to last for everyone.

For example, if you want all sudo sessions to last an hour, add the highlighted line to the file and save.

#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults        env_reset, timestamp_timeout=60
Defaults        mail_badpass
Defaults        secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

# Host alias specification

Save the file and exit.

That’s it!

Conclusion:

This post shows you how to quickly and easily adjust sudo session time limits on Ubuntu 18.04 | 16.04 systems. If you find any error above, please use the form below to report it.

Thanks,

You may also like the post below:


Discover more from Geek Rewind

Subscribe to get the latest posts to your email.

Like this:



Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Blog at WordPress.com.

Discover more from Geek Rewind

Subscribe now to keep reading and get access to the full archive.

Continue reading