0
votes

I am working on a project in university and therefore have to use the testbed servers situated in a university building. The problem is that I can only connect to those servers when I am in the "right" network of the university. Even if I use the university WLAN with my notebook I cannot connect to the testbed directly.

The only possibility is to first connect to a machine (call it "Gate") that is in the right subnet. I can do this via ssh (tested and it works) even from my home computer. From this machine I can connect to all testbed machines (tested and it works)

Now I want to develop my code on my laptop und distribute it on all machines (3x testbed servers) AND start it right after I distributed it. I thought of using rsync for this which works fine when I do not have to do an "indirect" rsync (first rsync it to a directory on the gate and then rsync to all testbed servers)

This works fine when I do it manually. But I want to do it in a shell script. It should be as comfortable as possible as I have to change my code many times and distribute to test it.

All machines run ubuntu, except of the gate which runs xubuntu (shouldn't be a problem, I think)

My first try was this

rsync -ra -e "ssh -p 24" src [email protected]:Schreibtisch/_rsync_tmp/
ssh -T [email protected] -p 24 << EOF 
    cd ~/Schreibtisch/_rsync_tmp; 
    echo "sync to tb14";
    rsync -ra src stack@tb14:me/;
    echo "sync to tb15";
    rsync -ra src stack@tb15:me/;
    echo "sync to tb16";
    rsync -ra src stack@tb16:me/;
EOF

But for some reason I get the error message

sync to tb14

Permission denied, please try again.

Permission denied, please try again.

Permission denied (publickey,password).

rsync: connection unexpectedly closed (0 bytes received so far) [sender]

rsync error: unexplained error (code 255) at io.c(226) [sender=3.1.0]

I don't know why I get "permission denied". It didn't even ask me for my passphrase for the ssh key. When I log in to the gate and then execute rsync from right there, it works as expected.

Anybody has an idea? :) Is there an easier way to do a rsync to a system that is not directly reachable? (but via another system)

EDIT:

This seems to be working:

rsync -ra -e "ssh -p 24" src [email protected]:Schreibtisch/_rsync_tmp/
ssh -t -t [email protected] -p 24 'cd ~/Schreibtisch/_rsync_tmp; 
echo "sync to tb14";
rsync -ra src stack@tb14:me/;
echo "sync to tb15";
rsync -ra src stack@tb15:me/;
echo "sync to tb16";
rsync -ra src stack@tb16:me/;'

But now I have to enter the passphrase for each tb* host.

I tried ssh-add but get this message

Could not open a connection to your authentication agent.

What can I do?

1

1 Answers

0
votes

I found a solution!

rsync -ra -e "ssh -p 24" src [email protected]:Schreibtisch/_rsync_tmp/
ssh -t -t [email protected] -p 24 'cd ~/Schreibtisch/_rsync_tmp; 
eval $(ssh-agent);
ssh-add;
echo "sync to tb14";
rsync -ra src stack@tb14:me/;
echo "sync to tb15";
rsync -ra src stack@tb15:me/;
echo "sync to tb16";
rsync -ra src stack@tb16:me/;'

This works like I want :) The only problem is that the ssh-agent is started again every time and I have to enter the PW. But better than 3x :)