Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

For me, networks are a very "opaque" thing, and even with reading a lot of tutorial about SSH, I do not understand how to create a basic tunnel to transfer my files.

The configuration is the following :

My Computer --[Internet]--> Bridge Machine --[Local Network]--> Final Machine

Currently I do the following :

1) Connect to the Bridge Machine with :
ssh -X username@bridgemachine.something.fr

2) Connect to the Final Machine with :
ssh -X username@finalmachine

3) I copy the address of files I need (for example .../mydirectory)

4) Then I deconnect from the finalmachine with :
exit

5) I copy the files to the bridge :
scp -r username@finalmachine:/.../mydirectory .

6) I deconnect from the bridge with :
exit

7) I copy the files to my machine :
scp -r username@bridgemachine.something.fr:/.../mydirectory .

Which is quite complicated. My question is basic : how to simplify this using a SSH tunnel ?

(and please explain me the signification of each command line you write, to understand what each line really do and to avoid to use it like a magical thing. Furthermore if some ports number are used, explain me if I can pick a completely random number or if I have to choose a specific one.)

share|improve this question

migrated from stackoverflow.com Nov 15 '12 at 3:19

This question came from our site for professional and enthusiast programmers.

1  
Google on "ssh tunnel tuorial" gives popcornfarmer.com/2009/01/ssh-tunneling-tutorial & revsys.com/writings/quicktips/ssh-tunnel.html & aperiodic.net/phil/ssh and many others references –  Basile Starynkevitch Nov 11 '12 at 7:17
    
You could also just run your local ssh to run scp on the bridge machine (give it the scp command to run), then run scp on the local machine, then wrap that all in a shell script. You could easily make one command out of it that way. –  Keith Nov 11 '12 at 14:59

1 Answer 1

Set up an ssh config file:

~/.ssh/config

This file will help in a number of ways, but ultimately will allow you to do all this with one step.

First, set up aliases for each machine

Host bridge
User username

Host final
User username

Now you can use "ssh -X bridge" to connect with the first machine.

For this next step you'll need netcat on each machine (try "which nc") to check. Then, use a ProxyCommand with your 'final' machines config so it reads:

Host final
User username
ProxyCommand ssh -CAYq bridge exec nc %h %p

This command sends whatever you want through the central machine to host %h on port %p (meaning if you want to send other app data through on different ports you can - so long as this connection is open)

If you have keys set up there will be no password prompts either, if not: you'll be prompted for bridge's first, then final's.

Now "ssh final" should work, as well as:

scp -r final:/.../directory .
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.