PyCharm: Configuring multi-hop remote Interpreters

2019-02-06 04:42发布

问题:

To connect to the computer at my office I need to run ssh twice. First to connect to the host-1 and then from host-1 to host-2 and each one has different credentials. However the configuration menu in Pycharm only accepts one ssh tunnel.

Configure Remote Python Interpreter dialog box

Is there any way to set a multi-hop ssh to have access to the interpreter and data files on the host from local?

回答1:

You can use port forwarding on ssh. If local system is A, the next ssh hop is B, and the target hop is C, open a terminal and run:

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

You can substitute 6000 with any port. Now you can ssh into the ssh server on C on another terminal with:

ssh -p 6000 <user_serverC>@localhost

Keep in mind not to close the first terminal!

The same goes for the PyCharm. Just set the remote interpreter connection through ssh with the following configuration:

  • host: localhost
  • port: 6000
  • user: user_serverC