To set the sudo password timeout value, use the passwd_timeout parameter. First, open the /etc/sudoers file with superuser 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 commands you execute or disable password prompt forever by setting the value -1.

 

The defaults parameters have set in my /etc/sudoers file.

 

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.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $131.99 a month.

Was this answer helpful?

Still stuck? Open a ticket