问题描述
要连接到我办公室的计算机,我需要运行 ssh 两次.首先连接到主机 1,然后从主机 1 连接到主机 2,每个都有不同的凭据.但是 Pycharm 中的配置菜单只接受一个 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.
有没有办法设置多跳 ssh 以从本地访问主机上的解释器和数据文件?
Is there any way to set a multi-hop ssh to have access to the interpreter and data files on the host from local?
推荐答案
您可以在 ssh 上使用端口转发.
You can use port forwarding on ssh.
在您的本地系统上:
ssh -L 6000:<target_server_ip>:22 <proxy_server_user>@<proxy_server_ip>
您现在应该连接到代理.您可以用任何端口替换 6000.
You should be connected to the proxy now. You can substitute 6000 with any port.
现在您可以通过 ssh 连接到另一个终端上的目标服务器:
Now you can ssh into the target server on another terminal with:
ssh -p 6000 <target_server_user>@localhost
3.配置 PyCharm
记住不要关闭第一个终端!
3. Configure PyCharm
Keep in mind not to close the first terminal!
PyCharm 也是如此.只需使用以下配置通过 ssh 设置远程解释器连接:
The same goes for the PyCharm. Just set the remote interpreter connection through ssh with the following configuration:
- 主机:本地主机
- 端口:6000
- 用户:target_server_user
这篇关于PyCharm:通过 SSH 配置多跳远程解释器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!