0

I have a bash script that installs a lot of software. The whole process takes around 1h therefore I would like to increase the sudo timeout variable. I see it is possible as described here: Increase duration of Sudo.

However, I cannot find a description for the command line anywhere...
In my case I would like to make this change from within the script. I could put something like: sudo echo 'Defaults timestamp_timeout=300' >> /etc/sudoers at the first line within the bash script. This, however, is not allowed.

maciek
  • 165

1 Answers1

0

I will post an answer to my problem in case anyone else runs into such issue in the future.
Thanks for the help @steeldriver.

Indeed, it is better to use sudo on the whole script and then escape commands within which specifically need to be run as the user with a prefix: sudo -u $SUDO_USER. Importantly, when the script is run with root privileges the $HOME changes, so be careful. In order to refer to the original user's home create a variable:

USER_HOME=$(sudo -u $SUDO_USER -H -s eval 'echo $HOME')

and then operate on paths with the prefix of $USER_HOME, if required.

maciek
  • 165