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.

10
5 comments
Avatar
Permanently deleted user

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
Avatar
Permanently deleted user

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
Avatar
Permanently deleted user

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)
2
Avatar
Permanently deleted user

Apart from the general SSH tunnel setup (via `-L` key as stated above or `.ssh/config` with LocalForward), the issue could be due to quirks of sftp/scp. If in the shell config there is anything which has output - it hangs completely scp/sftp. So if ssh works fine for you, but scp doesn't - remove any non-standard lines from default ssh config (e.g. `bashrc`). Few examples are:

  • `exec /bin/zsh -l`
  • `echo 'something'`
0

Feature Request: It would be really convenient if pycharm ( and perhaps other IntelliJ IDE's)  could use the default ssh configuration file ($HOME/.ssh/config on most unix like enviornments) to connect to SSH hosts.

I have all my work hosts configured over there with the required port forwards, ssh-hops etc.

 

6

Please sign in to leave a comment.