sudo to super-user after scp

Solution 1:

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:

$ ssh other-host sudo /path/to/deployment.script

If not, then you can have sudo take its input from a file:

$ ssh other-host 'sudo -S /path/to/deployment.script < password.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.

Solution 2:

Create a key pair on the remote host just for this purpose add it to root's authorized keys file on the server your are deploying to. In front of the key add 'command="cat - >> file.name;deploy_script.sh" ,no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty' On the remote host run "cat /path/to/file|ssh -i /path/to/key"

You can also set this up with scp using the following in the authorized keys file

command="scp -t /destination/directory/;deploy_script.sh",no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty ssh-dss xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx user@remote_server

If you can't get access to root's authorized_keys2 file combine it with password less sudo. If that is not allowed use ssh,scp and expect.

Solution 3:

You could do this fairly easily with some kind of cron based solution

#!/bin/bash

if [ -f /path/to/deployment.script ]; then
    mv /path/to/deployment.script /path/to/somewhere/else
    do_deployment
fi

Running a script like that every few minutes from cron as root should do what you need. There's probably a more elegant way to do this, but this is the simplest/quickest that came to mind.