【问题标题】:Google cloud engine, ssh between two centos7 instances fails谷歌云引擎,两个centos7实例之间的ssh失败
【发布时间】:2015-02-23 20:04:44
【问题描述】:

我已经设置了 2 个 Google Compute Engine 实例,我可以使用 gcloud compute ssh 命令创建的密钥轻松地在这两个实例中进行 SSH。但是当我尝试以下...

myself@try-master ~] ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa
myself@try-master ~] cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
myself@try-master ~] chmod 0600 ~/.ssh/authorized_keys
myself@try-master ~] ssh-copy-id -i ~/.ssh/id_rsa.pub myself@try-slave-1

...它不起作用,并且ssh-copy-id显示以下消息:

Permission denied (publickey,gssapi-keyex,gssapi-with-mic)

如果我在 try-master 上复制 google_compute_engine 私钥和公钥,并且可以使用它来登录两个实例,但我发现通过网络移动私钥并不令人满意。我想这和topic有点关系:

如何解决?

[1]https://cloud.google.com/compute/docs/instances#sshbetweeninstances

【问题讨论】:

    标签: ssh google-compute-engine ssh-keys


    【解决方案1】:
    1. 使用 CentOS7 映像,并使用 CentOs7 作为本地主机:

      gcloud compute instances create try-master --image centos-7
      gcloud compute instances create try-slave-1 --image centos-7
      

    这可以通过在初始 SSH 密钥设置期间使用身份验证转发来解决:

    1. 在本地机器上设置一次身份验证转发(注意“-A”标志)。首先你需要运行:

      eval `ssh-agent -s`

      然后

      ssh-add ~/.ssh/google_compute_engine
      gcloud compute ssh --ssh-flag="-A" try-master
      
    2. 执行上述步骤(从 keygen 到 ssh-copy-id) myself@try-master ~] ssh-keygen -q -t rsa -N "" -f ~/.ssh/id_rsa myself@try-master ~] cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys myself@try-master ~] chmod 0600 ~/.ssh/authorized_keys myself@try-master ~] ssh-copy-id -i ~/.ssh/id_rsa.pub myself@try-slave-1 myself@try-master ~] exit

    3. 在没有 SSH 身份验证转发的情况下再次登录 try-master: gcloud compute ssh try-master myself@try-master ~] ssh myself@try-slave-1 myself@try-slave-1 ~]

    最初的方法不起作用,因为 GCE 实例默认只允许公钥身份验证。因此,ssh-copy-id 无法针对 try-slave 进行身份验证以复制新的公钥,因为在 try-slave 中还没有在 try-master 中配置的公钥。

    使用身份验证转发,来自本地计算机的私钥从本地计算机转发到 try-master,然后从那里转发到 try-slave。 try-slave 中的 GCE 客户经理将从您的项目元数据中获取公钥,因此 ssh-copy-id 将能够复制工作。

    【讨论】:

    • 我已将您的回复重新发布为“答案”,以结束此问题。
    • 这对我来说仍然失败 ssh-copy-id -i ~/.ssh/id_rsa.pub name@instance /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys Permission denied (publickey,gssapi-keyex,gssapi-with-mic).
    • 我刚刚再次检查,它运行良好......我正在编辑答案并将eval $(ssh-agent)替换为eval `ssh-agent -s`
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-13
    • 2019-01-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多