For deploying code to a server I run a script which scp's the deployment file onto the server using my private key .
But after scp I have to manually ssh to the machine
sudo to a superuser account and run a deployment script .
I would like to automate the second step too , but cannot figure out how to .
Any other alternatives to this two step process ?
Best Answer
If whomever controls the sudoers file will change it so that you can run certain commands without a password, it will be as simple as running:
If not, then you can have sudo take its input from a file:
But, don't do that as that means you're putting your password into a file. And the server admin should kick your ass for that.
A better option than all of the above is to have the server admin set up an entry in root's authorized_keys file that is only allowed to run the deployment script. This way, to run the script you only need to ssh into the server as root with a special key.