multi-hop ssh for remote development

Hi guys,

My python interpreter is on a machine which I have to do multi-hop ssh to login to. It has a local ip address and cannot be accessed from outside the local network. So I have to ssh to the gateway first and then ssh to my machine.

Anyone has any ideas how I can set up the remote interpreter in this scenario?

Thanks!

Edit: I have set up ssh forwarding and both ssh and sftp work without any problem. But in Pycharm I get the "Connection failed" error.

3 comments
Comment actions Permalink

Hi guys,

Sorry for the long delay. I figured out the solution.

I needed to ssh to the machine through gateway with portforwarding port 22 of that machine any arbitrary port on localhost. So that if I ssh to localhost with the forwarded port, I can access the machine behind the gateway. Once the ssh is OK, in PyCharm I entered localhost with the port I used for forwarding and VIOLA!

PROBLEM SOLVED.

-1
Comment actions Permalink

Hi Mehran Pesteie

 

Thank you for the solution. I have successfully set up the ssh as you described using following command.

ssh -l username -L 7777:work:22 gate cat -

and then in another shell when I executed the following command 

ssh -p 7777 localhost 

I can shh to my work machine directly.

But I do not understand the last bit of your solution. How can I now setup the PyCharm by entering localhost with port 22?It does not work for me. Could you kindly guide me here.

Cheers!!

 

 

1
Comment actions Permalink

https://stackoverflow.com/questions/37827685/pycharm-configuring-multi-hop-remote-interpreters-via-ssh

this solved it for me.

When you are on A and want to connect to server C through server B:

    ssh -L 6000:<server C IP>:22 <user_serverB>@<server B IP>

Here server C is the target machine and server B the gate machine. And then in the remote interpreter configuration

(File>Setting>Projet>project interpreter>click on small wheel button>add remote):

  • host: localhost
  • port: 6000
  • user: user_serverC   (for me same as user_serverB)
1

Please sign in to leave a comment.