mehrtash
mehrtash

Reputation: 930

PyCharm: Configuring multi-hop remote Interpreters via SSH

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?

Upvotes: 44

Views: 21005

Answers (3)

FatherShawn
FatherShawn

Reputation: 213

For users on ssh version 7.3 or later this can be simplified using the ProxyJump parameter.

Host bastion
   Hostname bastion.domain.com
   User bastion-user

Host servera
   Hostname servera.lan.local
   User servera-user
   ProxyJump bastion

Upvotes: 5

Harald Thomson
Harald Thomson

Reputation: 784

PyCharm seemingly parses the local .ssh/config too.

If you already have configured ssh hopping there, you can just specify the target server in your pycharm ssh-config.

~/.ssh/config (source)

Host bastion
   Hostname bastion.domain.com
   Port 2222 # a non-standard port is a good idea
   User ironicbadger

Host servera
   Hostname servera.lan.local
   User servera-user
   ProxyCommand ssh bastion -W %h:%p

in pycharm: Host servera, User name server-user

Upvotes: 9

Amir
Amir

Reputation: 2425

You can use port forwarding on ssh.

1. Open a terminal and run:

On your local system:

ssh -L 6000:<target_server_ip>:22 <proxy_server_user>@<proxy_server_ip>

You should be connected to the proxy now. You can substitute 6000 with any port.

2. (optional) Test

Now you can ssh into the target server on another terminal with:

ssh -p 6000 <target_server_user>@localhost

3. Configure PyCharm

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: target_server_user

Upvotes: 77

Related Questions