LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 08-02-2012, 01:16 AM   #1
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
rsync+ssh: chain 4 boxes together


Hi Guys,

network layout (all RHEL5 systems):

box1 ---> box2 ---> box3 ---> box4

Need to rsync+ssh ie transparent pipe from 1->4 (going via box2 & box3 as per diagram).
Same user on all and ssh-auth-keys enabled & tested ok.
Reckon I need to use ssh tunnels, but can't quite get it working.

I'm using setups like this eg on box1
Code:
nohup /usr/bin/ssh -nNTx -L 8890:box2:8890 user@box2 &
& so on for box2 & box3

Edit: cmd
Code:
rsync -avz /home/user/test.dat --progress --inplace  --rsh='ssh -p8890' user@box1:/home/user
Eventually it times out with
Code:
ssh: connect to host box1 port 8890: Connection timed out
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
See also as run on box1
Code:
rsync -avz /home/user/test.dat --progress --inplace  --rsh='ssh -p8890' user@box2:/home/user
ssh: connect to host box2 port 8890: Connection refused
rsync: connection unexpectedly closed (0 bytes received so far) [sender]
rsync error: unexplained error (code 255) at io.c(600) [sender=3.0.6]
Strangely enough, I've never had to implement an ssh tunnel and chaining 4 systems together is confusing me

I think I need to define a listener on box4, but I'm not sure what, if any?

Thanks for any solns

Last edited by chrism01; 08-02-2012 at 01:25 AM.
 
Old 08-02-2012, 03:35 AM   #2
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

you seem to be trying to do this the "old fashioned" way with local port forwarding. It's much easier (especially with multihop) to used the "ProxyCommand" in your ~/.ssh/config
Here is how I would do what you are trying to achieve.

Add the following to your ~/.ssh/config on box1
Code:
Host box4
     ProxyCommand ssh -qax -W %h:%p box3

Host box3
     ProxyCommand ssh -qax -W %h:%p box2
Now from box1 you should be able to get to box4 just by doing:
Code:
ssh box4
and rsync should work just the same.

One caveat:
The -W option was introduced to ssh somewhat recently (sorry I don't know the version number).
So if you boxen don't have ssh with -W you need to use a slight hack with netcat.

In this case you would have lines like:
Code:
Host box4
     ProxyCommand ssh -qax box3 nc %h %p
If you have different usernames on the different boxen just declare the username for each box in its section. Eg
Code:
Host box4
   User box4username
   ProxyCommand ssh -qax -W %h:%p box3
HTH,

Evo2.
 
Old 08-02-2012, 11:40 AM   #3
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
I like evo2's solution.

I was also going to suggest a simple TCP forwarding service (e.g. rinetd) to accept connections from box1 -> box2, from box2 -> box3, and from box3 -> box4. IMO, it's not strictly necessary to authenticate at every host along the way (and the channel is already encrypted). rinetd can be configured for IP-level access control.
 
Old 08-02-2012, 07:57 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I like the idea of evo2's soln as well.
So long as it gets encrypted before it starts being transmitted, that's good enough.
(As it happens, I've never had to actually setup rsync or ssh tunnels before... )

Anyway, I put the proxy cmds in (using nc as the target systems are RHEL5.0; test is on 5.7), which is simpler anyway.
I've also copied the (dsa) ssh keys ie user1@box1 to the same user on box2, box3, box4.
As this is a test LAN, the boxes can all see each other direct, so I used /etc/hosts.deny on box4 to deny sshd from box1, box2 to enforce/check I'm using the proxies.

It all good so thx a lot(!) to evo2.


PS as it happens, the App team will not be using this now, but I'm documenting the technique anyway, for future ref for myself

Last edited by chrism01; 08-02-2012 at 10:20 PM. Reason: Took me a few tests/fixes to get right; posted failures too soon
 
Old 08-02-2012, 09:19 PM   #5
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi Chris,

you say that you have copied the "keys" plural. You should only need to copy one key file: the dsa public key, and append its contents to ~/.ssh/authorized_keys file on boxs 2-4. Using ssh-copy-id normally works well for this. Eg
Code:
ssh-copy-id -i ~/.ssh/id_dsa.pub box2
You may get the most pertinent information from the sshd logs. If you don't have access to these you can start up your own sshd instance in debug mode on an alternative port. Eg log into box3 and run
Code:
/usr/sbin/sshd -d -p 9999
then put a Port option section in your box1:~/.ssh/config
Code:
Host box3
  Port 9999
  IdentityFile ~/.ssh/id_dsa
  ProxyCommand ProxyCommand ssh -qax box2 nc %h %p
Then try again.

Finally (and I think this is a long shot) I wonder if it would make any difference if you were explicit about what private key you want to use. Eg
Code:
Host box3
  IdentityFile ~/.ssh/id_dsa
  ProxyCommand ProxyCommand ssh -qax box2 nc %h %p
HTH,

Evo2.
 
Old 08-02-2012, 10:24 PM   #6
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Aargh, must have left this thread open, so I edited the above ... sorry.
Anyway, as you can see, you are essentially right.
Actually, I'm now using a much simpler rsync cmd, with the above technique (as credited to you)
Code:
[user@box1 ~]$ rsync -av test.dat -e ssh --progress user@box4:/home/user
sending incremental file list
test.dat
          19 100%    0.00kB/s    0:00:00 (xfer#1, to-check=0/1)

sent 112 bytes  received 31 bytes  95.33 bytes/sec
total size is 19  speedup is 0.13
& it works a treat

Thx again
 
Old 08-03-2012, 12:18 AM   #7
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and CentOS
Posts: 6,724

Rep: Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705Reputation: 1705
Hi,

glad I was able to help, you can put it away in your bag of tricks for later.

It's refreshing to help with a "proper" question... trying to help out over on the Newbie forum can be become quite frustrating after a while.

Evo2.
 
1 members found this post helpful.
Old 08-05-2012, 06:01 PM   #8
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Original Poster
Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
I hear that

Stick around, I may have qns on KVM later; trying to teach myself at home and got messed up with the networking part; managed to cut myself off from the internet
Section 2.6 http://linux.dell.com/files/whitepap..._made_easy.pdf

I'll open a new thread for the qns..

Last edited by chrism01; 08-05-2012 at 06:10 PM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] rsync fails in cron - ssh key prob for rsync? jonathansfl Linux - Server 6 12-09-2010 09:48 AM
SSH chain tunneling netpumber Linux - General 3 11-14-2009 12:58 PM
How to Best rsync 2 boxes (Same OS, Different Arch) WhisperiN Linux - Server 4 11-11-2009 05:35 AM
rsync between 2 boxes using usb cable tequesta Linux - General 5 10-23-2008 12:53 PM
Rsync server vs rsync over ssh humbletech99 Linux - Networking 1 10-18-2006 12:10 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 09:37 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration