开发者

How to ssh to a remote server behind multiple firewalls? [closed]

开发者 https://www.devze.com 2023-02-02 01:50 出处:网络
Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed. This question is off-topic. It is not currently accepting answers.

Want to improve this question? Update the question so it's on-topic for Stack Overflow.

Closed 11 years ago.

Improve this question

Here is my situation

  • I could access Server A from my home laptop via ssh.
  • Server B is only accessible from Server A via ssh.
  • Server C is only accessible from Server B via ssh.

Is there anyway that I could configure my .ssh/config so that I could ssh to Server C directly from my laptop ? I need this because I need regularly transfer files from Server C back to my laptop. I'm using 'scp' but go through this ssh hierarchy manually is too painful. I'm wondering wheth开发者_运维知识库er there's a more straight-forward to do this via the magic of ssh.


You want to set up SSH tunnels to to allow SSH like this:

A => B
B => C

Here's an example of how to setup the tunnel to B through A on Linux:

ssh -f myusername@hostA -N -L 4444:hostB:22

Then, you should be able to ssh to port 4444 on hostA, and have that forwarded to port 22 (where SSH commonly runs) on hostB. After running the above command, try this:

ssh -p 4444 hostA

That should connect you to hostB. You may have to change ports for this to work, if port 4444 on hostA is already being used you'll have to pick a different port. Assuming that this works, you can use the same command with different hostnames to set up the tunnel from B => C:

ssh -f myusername@hostA -N -L 4444:hostB:4444
ssh -f myusername@hostB -N -L 4444:hostC:22

This is also useful if you want to set up a SOCKS proxy for web browsing. I do this so that my web traffic looks like it's coming from my university, so that I can use online access to scientific journals.

References:

  • Tunneling protocol
  • Breaking firewalls with OpenSSH and Putty
  • How to create an SSH tunnel using Putty, and then use that tunnel as a Firefox SOCKS proxy
0

精彩评论

暂无评论...
验证码 换一张
取 消