SSH tunneling: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
Line 1: | Line 1: | ||
This is a simple guideline for using ssh tunneling. | This is a simple guideline for using ssh tunneling. | ||
ssh connection uses port 22 to communicate by default. | <pre>ssh</pre> connection uses port 22 to communicate by default. | ||
Suppose we have this situation: | Suppose we have this situation: | ||
Line 7: | Line 7: | ||
[[File:SSH tunneling diagram.png|800px|frameless|none]] | [[File:SSH tunneling diagram.png|800px|frameless|none]] | ||
haha.myhome cannot directly connect to fox.fsu.edu, but | '''haha.myhome''' cannot directly connect to '''fox.fsu.edu''', but unable to connect to '''gateway.fsu.edu'''. | ||
For the interactive shell, that would be not a problem, | For the interactive shell, that would be not a problem, | ||
#from haha.myhome, login to gateway.fsu.edu | #from '''haha.myhome''', login to '''gateway.fsu.edu''' | ||
#from gateway.fsu.edu, login to fox.fsu.edu | #from '''gateway.fsu.edu''', login to '''fox.fsu.edu''' | ||
However, it is very clumsy to copy files from fox.fsu.edu to haha.myhome, there is no direct connection. | However, it is very clumsy to copy files from '''fox.fsu.edu''' to '''haha.myhome''', there is no direct connection. | ||
In this case, ssh tunning makes life easier. | In this case, ssh tunning makes life easier. | ||
To use gateway.fsu.edu as a bridge, bridge to fox.fsu.edu, port 22 to haha.myhome, port 9896, by using the following command | To use '''gateway.fsu.edu''' as a bridge, bridge to '''fox.fsu.edu''', port 22 to '''haha.myhome''', port 9896, by using the following command | ||
haha.myhome$ssh -N gatewayUser@gateway.fsu.edu -L 9896:fox.fsu.edu:22 | haha.myhome$ssh -N gatewayUser@gateway.fsu.edu -L 9896:fox.fsu.edu:22 | ||
After the bridge is established, port 9896 at | After the bridge is established, port 9896 at '''haha.myhome''' is connected to port 22 at '''fox.fsu.edu'''. So, we can either ssh, scp, or rsync by | ||
haha.myhome$ssh -P 9896 foxUser@localhost | haha.myhome$ssh -P 9896 foxUser@localhost | ||
haha.myhome$scp -P 9896 foxUser@localhost:<files> <haha.myhome_destination> | haha.myhome$scp -P 9896 foxUser@localhost:<files> <haha.myhome_destination> | ||
haha.myhome$rsync -arvzp -e 'ssh -p 9896' foxUser@localhost:<files> <haha.myhome_destination> | haha.myhome$rsync -arvzp -e 'ssh -p 9896' foxUser@localhost:<files> <haha.myhome_destination> |
Revision as of 14:28, 29 April 2022
This is a simple guideline for using ssh tunneling.
ssh
connection uses port 22 to communicate by default.
Suppose we have this situation:
haha.myhome cannot directly connect to fox.fsu.edu, but unable to connect to gateway.fsu.edu.
For the interactive shell, that would be not a problem,
- from haha.myhome, login to gateway.fsu.edu
- from gateway.fsu.edu, login to fox.fsu.edu
However, it is very clumsy to copy files from fox.fsu.edu to haha.myhome, there is no direct connection.
In this case, ssh tunning makes life easier.
To use gateway.fsu.edu as a bridge, bridge to fox.fsu.edu, port 22 to haha.myhome, port 9896, by using the following command
haha.myhome$ssh -N gatewayUser@gateway.fsu.edu -L 9896:fox.fsu.edu:22
After the bridge is established, port 9896 at haha.myhome is connected to port 22 at fox.fsu.edu. So, we can either ssh, scp, or rsync by
haha.myhome$ssh -P 9896 foxUser@localhost haha.myhome$scp -P 9896 foxUser@localhost:<files> <haha.myhome_destination> haha.myhome$rsync -arvzp -e 'ssh -p 9896' foxUser@localhost:<files> <haha.myhome_destination>