繁体   English   中英

如何使用 PyCharm 通过 IAP 隧道远程访问 VM

[英]How to Remote to a VM over an IAP tunnel with PyCharm

我有一个没有分配外部 IP 地址的 google VM 实例。 我打算通过安装在本地计算机(运行 macOS)上的 PyCharm 建立 SSH 连接。

这可以通过gcloud IAP 隧道在终端中完成:

gcloud compute ssh <instance_name> --tunnel-through-iap

为实例添加到~./ssh/config的条目如下:

Host compute.<instance_id>
  HostName compute.<instance_id>
  IdentityFile /Users/<user_name>/.ssh/google_compute_engine
  CheckHostIP no
  HostKeyAlias compute.<instance_id>
  IdentitiesOnly yes
  StrictHostKeyChecking yes
  UserKnownHostsFile /Users/<user_name>/.ssh/google_compute_known_hosts
  ProxyCommand /Users/<user_name>/miniconda3/bin/python3 -S /Users/<user_name>/google-cloud-sdk/lib/gcloud.py beta compute start-iap-tunnel <instance_name> %p --listen-on-stdin --project=<project_name> --zone=us-central1-a --verbosity=warning
  ProxyUseFdpass no
  User <user_name>

使用VS Code的Remote-SSH插件,可以直接使用这个设置建立SSH连接没有问题( 示例)。

但是,我很难通过 PyCharm 设置连接。SSH 配置选项卡采用:

 - Host: compute.<instance_id>
 - User name: compute.<instance_id>
 - Port: 22
 - Authentication type: key pair
 - Private key file: path to ~/.ssh/google_compute_engine

并抛出 Host 格式不正确的异常。 如果我尝试将 VM 实例的内部 IP 地址作为主机,连接超时。

在 PyCharm 的 VS Code 中是否有类似于Remote-SSH的插件可以与 IAP 隧道一起正常工作? 或者可以通过任何其他方式设置它而无需向 VM 实例公开或分配外部 IP?

我知道已经有一段时间了,但我只是在做同样的事情。 我在 ~./ssh/config 中使用了相同的配置条目,但是 PyCharm 正在做一些检查以确保顶级主机值有效(即使它没有被使用)。 我用可以通过验证检查的东西替换了它,但我知道我永远不会真正使用它(以避免潜在的冲突)。

例如,您可以更新为:

Host mahmoud.local
  HostName compute.<instance_id>
  IdentityFile /Users/<user_name>/.ssh/google_compute_engine
  CheckHostIP no
  HostKeyAlias compute.<instance_id>
  IdentitiesOnly yes
  StrictHostKeyChecking yes
  UserKnownHostsFile /Users/<user_name>/.ssh/google_compute_known_hosts
  ProxyCommand /Users/<user_name>/miniconda3/bin/python3 -S /Users/<user_name>/google-cloud-sdk/lib/gcloud.py beta compute start-iap-tunnel <instance_name> %p --listen-on-stdin --project=<project_name> --zone=us-central1-a --verbosity=warning
  ProxyUseFdpass no
  User <user_name>

那么当你在PyCharm配置SSH连接时,你会想要使用Host = mahmoud.local

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM