0

I have 3 hosts:

Ipaddresses: hostA = 10.108.190.23 
             hostB = 10.108.190.82
             hostC = 128.221.252.67

I can ping hostB from hostA and hostC from hostB....There is no direct path from hostA to hostC

I want to run a script on hostA which would start ntpd daemon on hostB and hostC and also transfer some files.

Using paramiko I have been able to do that from hostA to hostB but then I am stuck. I tried to send a python script to hostB which would start the ntpd daemon on hostC but that didn't work as the pythong script on hostB is making an ssh connection using subprocess module since paramiko is not available on hostB and I am not allowed to install it either.

Could someone please help me to understand how to perform this double ssh? Also when I use paramiko to connect to remote machine and execute code, does the code get executed on my machine or remote machine?

llrs
  • 3,308
  • 35
  • 68
anukalp
  • 2,780
  • 5
  • 15
  • 24
  • This is called "multi-hop ssh" – Eric Feb 04 '14 at 10:47
  • 1
    possible duplicate of [SSH to machine through a middle host](http://stackoverflow.com/questions/6366652/ssh-to-machine-through-a-middle-host), more specifically [this answer](http://stackoverflow.com/questions/6366652/ssh-to-machine-through-a-middle-host/13388479#13388479) – lanzz Feb 04 '14 at 10:52
  • Use the code from http://stackoverflow.com/questions/20472288/python-ssh-password-auth-no-external-libraries-or-public-private-keys/20472419#20472419 and then simply do `ssh 10.0.0.1 'ssh 10.10.0.2 \' ssh 10.20.0.3\''` ? – Torxed Feb 04 '14 at 10:54

1 Answers1

1

Since ssh will start a shell on the remote computer, this task might be easier to solve in shell programming than artificially introducing a Python script. You would end up by using the shell to start your Python script which would only complicate things unnecessarily.

The best solution actually depends on what you want to do.

Log in on C via B from A

A$ ssh B
B$ ssh C

(No surprise here, I'm sure.)

Start a command on C

A$ ssh B 'ssh C ls'

This will start the command ls on host C. It is necessary that the login itself does not query any passwords from the tty. It is okay if it asks you via a popup window, though.

Transmit a file from C to A

A$ ssh B 'ssh C "cat /path/to/remotefile"' > /path/to/localfile

The same restrictions concerning passwords apply. Better use proper keys anyway so you can login without being asked for a password.

Transmit a file from A to C

A$ ssh B 'ssh C "cat > /path/to/remotefile"' < /path/to/localfile

And again, password queries might interfere, so get rid of them.

Alfe
  • 56,346
  • 20
  • 107
  • 159