Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This question already has an answer here:

I am writing a script to download build and install a bunch of packages. Building sometimes takes a while, and installing requires root priviledges:

make; sudo make install

What happens alot is that when a build takes a while I need to keep entering my password. I want to be able to only enter it once. I could call the script with root access, but then (as I understand it) every call it makes will be with root priviledges. I don't want this because then, eg., many files and folders get created that can't be deleted without root access.

so what is the best way to do this?

share|improve this question

marked as duplicate by David Foerster, Eric Carvalho, Pilot6, 2707974, Galgalesh Apr 23 at 17:56

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

Use the timestamp_timeout parameter. Use visudo to edit the sudoers file:

sudo visudo

and modify the defaults line so it looks like this:

Defaults   env_reset,timestamp_timeout=60

this will keep your password for 60 minutes.

Modify this time as desired :)

share|improve this answer

The script can contain sudo calls themselves. If you then run the script with sudo it will cover all sudos in the script and should be ok

share|improve this answer
    
"I don't want this because then, eg., many files and folders get created that can't be deleted without root access" – Gauthier Feb 12 '15 at 13:25
    
The commands will have root access. The script is ran as rot, so it's child processes (the commands in the script) will be spawned and run as root. – ActionParsnip yesterday

Not the answer you're looking for? Browse other questions tagged or ask your own question.