I am creating a script which runs a series of command that would download a website to a machine and sets up everything.
So most of the commands require root access. For example adding a vhost in /etc/apache2/sites-available
, enabling it, restarting apache, etc...
So in order to do that, I need to run the script with sudo
.
sudo ./install-website.sh
The website is located on a server with a git repository which is setup with a password-less SSH access. But that only works for the user dan
since the keys are in my home folder and not in the root's home folder.
So when it reaches this part:
git clone [email protected]:git-repo $PATH_TO_INSTALLATION
Since I started the script with sudo
, the user that is trying to initiate the git command is root. So the host keeps asking for the host's user's password.
I have tried the following command:
sudo -u $SUDO_USER git clone [email protected]:git-repo $PATH_TO_INSTALLATION
But it was still asking for the host's user's password.
Is it possible to tell sudo
to use the $SUDO_USER
's home path?
Most of the stuff are variables, and have to be variables as I will run this on more than 1 machine.