3

I have a long running script which runs as normal user then then has sudo make install towards the end which (if I don't notice it finishes within 5 minutes) times out and fails.

In man sudoers it describes this option to change how long it waits:

passwd_timeout' Number of minutes before the sudo password prompt times out, or 0 for no timeout. The timeout may include a fractional component if minute granularity is insufficient, for example 2.5. The default is 5.

This works globally - for example setting timeout to 15 seconds

~ $ sudo grep passwd /etc/sudoers    
Defaults passwd_timeout=0.25
~ $ sudo -k                          
~ $ date && sudo date && date || date
Fri 17 Apr 2020 10:23:26 CEST
[sudo] password for hali: 
sudo: timed out reading password
Fri 17 Apr 2020 10:23:41 CEST
~ $

However I'd like to leave the default sudo password timeout as 5 minutes but be able to have this specific sudo in my script wait forever for a password. Is it possible to set an individual password timeout on the sudo command or is there some other way to make my script wait indefinitely for me to enter my password?

There is no mention of this password timeout setting in man sudo - the only timeout option is -T which is "Used to set a timeout for the command. If the timeout expires before the command has exited, the command will be terminated."

I'm not trying to enter my password via the script as in this question sudo with password in one command line? nor trying to change the length of time credentials are cached as in this one Change default sudo password timeout

This is my sudo version:

~ $ sudo -V
Sudo version 1.8.31p1
Sudoers policy plugin version 1.8.31p1
Sudoers file grammar version 46
Sudoers I/O plugin version 1.8.31p1
lx07
  • 3,266

1 Answers1

0

The sudo manpage says:

If authentication is required, sudo will exit if the user's password is not entered within a configurable time limit. This limit is policy-specific; the default password prompt timeout for the sudoers security policy is 0 minutes.

To configure this then you would need to change the sudoers security policy configurations, which I don't think you can do on the fly. The easiest workaround would be to request the password from the user with read and then piping the password into the sudo command using the -S flag.

read -s -p "Enter sudo password:" PASS # will wait as long as it takes

do whatever you want to do with sudo, providing the password on stdin with -S

echo "$PASS" | sudo -S date

Leon S.
  • 189