【问题标题】:Difference between the commands "gcloud compute ssh" and "ssh"命令“gcloud compute ssh”和“ssh”之间的区别
【发布时间】:2025-12-23 18:35:12
【问题描述】:

gcloud compute ssh comannd 和“只是”ssh 命令之间到底有什么区别?

我观察到即使我可以使用gcloud compute ssh 在两个实例之间轻松连接,但我无法使用ssh 命令进行连接。但是,手动设置 ssh-keys 后,ssh 命令可以正常工作。但是 gcloud 命令不应该处理密钥管理吗?而且如果是使用gcloud设置一次,为什么ssh命令不能正常工作

.

工作正常:

gcloud compute ssh instance_2
gcloud compute shh instance_1

.

如果不手动设置 ssh-keys 将无法工作:

ssh instance_2
shh instance_1

.

这个问题来自我遇到的另一个问题,这让我疯了好几天:OpenMPI: Permission denied error while trying to use mpirun

【问题讨论】:

    标签: linux ssh google-compute-engine google-cloud-platform


    【解决方案1】:

    gcloud compute ssh 将密钥对安装为 ~/.ssh/google_compute_engine[.pub]。 ssh 默认使用 ~/.ssh/identity[.pub]。

    您可以将 google 密钥对复制到默认名称:

    $ cp ~/.ssh/google_compute_engine ~/.ssh/identity
    $ cp ~/.ssh/google_compute_engine.pub ~/.ssh/identity.pub
    

    或者您可以指定调用 ssh 时使用的私钥:

    $ ssh -i ~/.ssh/google_compute_engine instance_name
    

    【讨论】:

      【解决方案2】:

      专用的 google 命令gcloud compute ssh instance 基本上在底层使用标准 ssh,但在上面做了一些魔术,例如安装密钥。在这个问题的答案中得到了很好的解释: How to get the ssh keys for a new Google Compute Engine instance?

      【讨论】: