通过 Remote Explorer 和 gcloud 将 VSCode 连接到 GCP 实例

问题描述 投票:0回答:0

我在 Windows 上使用 VSCode 和 gcloud shell 来尝试连接到 GCP 实例。

我使用

gcloud compute config-ssh
命令创建别名以连接到我的 GCP 实例

然后我将上一个 gcloud 步骤生成的

ssh <vm_name>.<region_stuff>.<project>-<project_id>
行添加到 VSCode 中的 Remote Explorer,您可以在其中输入 ssh 行进行连接并选择配置文件

我尝试连接 Remote Explorer,为远程计算机的操作系统选择 Linux,并在远程窗口打开时一直遇到此错误:

[21:47:20.078] Terminal shell path: C:\Windows\System32\cmd.exe
[21:47:20.428] > ]0;C:\Windows\System32\cmd.exe
[21:47:20.429] Got some output, clearing connection timeout
[21:47:20.447] > ssh: Could not resolve hostname <vm_name>.<region_stuff>.<project>-<project_id>: No 
> such host is known.
[21:47:20.480] > The process tried to write to a nonexistent pipe.
[21:47:21.757] "install" terminal command done
[21:47:21.757] Install terminal quit with output: such host is known.
[21:47:21.757] Received install output: such host is known.
[21:47:21.758] Failed to parse remote port from server output
[21:47:21.759] Resolver error: Error: 
    at m.Create (c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:584145)
    at t.handleInstallOutput (c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:582705)
    at t.tryInstall (c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:681555)
    at async c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:643798
    at async t.withShowDetailsEvent (c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:647116)
    at async t.resolve (c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:644848)
    at async c:\Users\Vedant Gannu\.vscode\extensions\ms-vscode-remote.remote-ssh-0.100.0\out\extension.js:1:720590
[21:47:21.766] ------

根据 Connecting VSCode and GCP 中的错误和答案,我按照解决方案将主机和主机名替换为外部 IP 地址。

但是有没有办法避免每次都必须这样做?就像运行和使用

gcloud compute config-ssh
中的 ssh 的整个要点是提供一个别名,而不必在 IP 更改时继续读取主机,对吗?有什么办法可以防止这种情况发生并实际使用别名进行连接吗?

ssh gcloud vscode-remote
© www.soinside.com 2019 - 2024. All rights reserved.