我有一个没有分配外部IP地址的Google VM实例。我打算通过在本地机器上安装的PyCharm(运行macOS)建立SSH连接。
可以通过终端使用
并且会因为主机格式不正确而抛出异常。如果我尝试将VM实例的内部IP地址作为主机,连接会超时。
是否有类似于VS Code中的
可以通过终端使用
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
并且会因为主机格式不正确而抛出异常。如果我尝试将VM实例的内部IP地址作为主机,连接会超时。
是否有类似于VS Code中的
Remote-SSH
插件的PyCharm插件可以与IAP隧道正常工作?或者还有其他方法可以设置,而无需将外部IP公开或分配给VM实例?