SSH into server, sudo later with Phing

95 Views Asked by At

We have a server that is set up so you can't log in with root directly. You first log in with a user, then run su and enter the password.

I need to SSH into a server, using phing, and sudo then run a command. I thought if I can get it working just via ssh, I can use that command in an exec task in phing, but can't even get the plain SSH right.

Is this possible?

I've tried the following:

ssh user@server 'su && cd /var/www/clients'
ssh user@server 'su && {{password}} && cd /var/www/clients'
1

There are 1 best solutions below

0
Siad Ardroumli On

You can use the SshTask and how-to-pass-the-password-to-su-sudo-ssh-without-overriding-the-tty.

<project name="ssh-with-later-sudo" default="run-cmd" basedir=".">
    <target name="run-cmd">
        <ssh username="user" password="password" host="server" command="echo password | sudo -S cd /var/www/clients" />
    </target>
</project>