rsync via multiple ssh connections with a key
I need to do a rsync from a target server with a server in the middle and I have the same public key on both the target and middle server. I want to use that key so I don't have to do password authentication.
local --ssh--> middle --ssh--> target
Reading Method 1 of Using rsync through a firewall makes it seems like this is doable but I have been able to figure out the ssh part of the syntax of the command yet.
When I try
ssh -i $KEY -A user@middle ssh user@target
I get
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,password).
Clearly the agent forwarding isn't happening as I was expecting it to.
Ideally I'd like to fit it all in one command without have to put anything in ~/.ssh/config files. What are all of the steps to do an rsync in this situation?
Thanks, Everett
The '-A' will only "carry" identities loaded into ssh-agent. ('-i' on the command won't be enough.)
How about this something like this;
ssh-agent sh -c "ssh-add test_ident; rsync -avr --rsh='ssh -TA hostA ssh -TA ' foo/ hostB:/var/tmp/foo/"
Personally I do this in two hops with the following script:
#!/bin/bash
ssh -fN [email protected] -L2211:target.foo:22
rsync "-e ssh -p 2211" /Users/me/dir1/ root@localhost:/backup/dir1/ -avz --progress --delete-after
rsync "-e ssh -p 2211" /Users/me/dir2/ root@localhost:/backup/dir2/ -avz --progress --delete-after
mod as required.
It seemed easier than playing with the rsync options and if your target and middle have your key you shouldn't be prompted.