Ask Your Question

How to set up a remote host through an SSH gateway

asked 2018-10-11 20:24:00 -0600

Y. Hidaka's avatar

updated 2019-03-13 10:29:27 -0600


I was able to set up a remote project to an SSH gateway, but what I really want is to create a remote project on a different server that can be only connected through this gateway. Could anyone please teach me on how to achieve this?



edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2018-10-12 08:47:00 -0600

updated 2019-03-06 22:13:11 -0600

Wingware Admin's avatar

If you can establish an ssh tunnel for ssh itself through the gateway then it'll probably work.  You'll need two tunnels, one from your local machine to a port on the gateway and another from that port on the gateway to the target host's port 22 (the default port for ssh).  If that works you can then ssh to the selected port on your localhost and actually end up on the target machine. 

Then you should be able to use that with Wing's remote development support if you check on the "User SSH Tunnel for username@localhost" option under the Advanced tab of the remote host configuration.I don't have a good way to try this here right now, but here is a guess at what might work. 

First establish a tunnel to the gateway from your localhost:

ssh -L 50022:localhost:50022 username@gateway

This will get you a prompt on the gateway and start forwarding port 50022 on your local host to port 50022 on the gateway.  Then type the following at the prompt on the gateway to establish a tunnel to the target host:

ssh -N -L 50022:localhost:22 username@targethost

This will foward port 50022 from the gateway to port 22, the default port for ssh, on the target host but the -N option tells it not to give you a prompt on the target host (remove that option if you do want one).  Now you should be able to ssh directly to the target host from your local host like this:

ssh -p 50022 username@localhost

Note that you can also do both ssh commands on one line typed on your local host to establish both hops in the tunnel at the same time:

ssh -L 50022:localhost:50022 username@gateway ssh -N -L 50022:localhost:22 username@targethost

Note that I randomly chose to use port 50022 for the forwarding, which should work if the port is available on the local and gateway hosts.  If not, you may need to change that.  The reason it's not 22 is that you don't want that tunnel to conflict with the existing ssh services on your local host and gateway.  Also, obviously, username@gateway and username@targethost need to be set to the correct ones for your systems.  But don't change 'localhost' since that is correctly referring to the localhosts on which the ssh command is being run (your local host and your gateway host for the second one).

edit flag offensive delete link more


Thank you very much for the clear and detailed instructions! I was experimenting with port forwarding tricks before asking a question here, but it was not working. My crucial mistake was that I was using some random unused port, instead of SSH default port 22, on targethost as the forwarded port.

Y. Hidaka's avatar Y. Hidaka  ( 2018-10-12 15:08:00 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2018-10-11 20:24:00 -0600

Seen: 901 times

Last updated: Mar 06 '19