[Linux] rsync/ssh question
Kwan Lowe
linux@flux.org
Wed, 21 Mar 2007 18:55:36 -0400 (EDT)
>> Is there a way to do this directly with rsync over ssh? Suggestions?
>
> If you can ssh from HostA to HostB and from HostB to HostC, then you can
> create an ssh tunnel from HostA to HostC via HostB.
>
> For example, establish an ssh tunnel like so:
>
> $ ssh -2 -N -L 12345:$HostC:22 $UserB@$HostB
>
> After you type in your password, push the tunnel into the background
> with Ctrl-Z followed by 'bg'. Start your rsync:
Using your suggestion, I'd started going along this route. The script I wrote was:
#!/bin/sh
set -x
DMZ_HOST=illusion
JUMP_HOST=janus
LOCAL_PORT=30000
LOCAL_ALIAS=local-alias
SOURCE=foo
DESTINATION=/tmp/foo2
echo nohup ssh -2 -N -L ${LOCAL_PORT}:${DMZ_HOST}:22 ${JUMP_HOST} &
# tba - check if tunnel exists (can bind to LOCAL_PORT)
nohup ssh -2 -N -L ${LOCAL_PORT}:${DMZ_HOST}:22 ${USER2}@${JUMP_HOST} &
rsync -a -e "ssh -p ${LOCAL_PORT}" ${SOURCE} ${LOCAL_ALIAS}:${DESTINATION}
A problem occured when I tried to connect on the local port. My known_hosts file
thinks that it's connecting locally so checks against the localhost key versus
HostC. This caused the second SSH connection to fail (Man In the Middle warning).
I copied the HostC known_host entry from HostB to HostA and renamed the hostname.
This got past the error... Still have to work out a few bugs but I think it'll get
there.
Thanks much!
>
> $ rsync -e "ssh -p 12345" $source $UserC@localhost:$destination_path
>
> That is just one of several ways.
>
> Good luck and please post back letting us know how it went.
--
* The Digital Hermit http://www.digitalhermit.com
* Unix and Linux Solutions kwan@digitalhermit.com