AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 799433
Accepted
Adron
Adron
Asked: 2016-08-27 17:16:19 +0800 CST2016-08-27 17:16:19 +0800 CST 2016-08-27 17:16:19 +0800 CST

Google Cloud 实例上的 Terraform ssh 错误?

  • 772

我今天一直在解决 Terraform Provisioner 与 ssh 的连接问题。到目前为止,我已经尝试过我以前认为的方法:

  provisioner "remote-exec" {
    inline = [
      "echo ${google_compute_instance.testing-elastic-1.network_interface.0.access_config.0.assigned_nat_ip}"]
      connection {
        type = "ssh"
        user = "root"
        private_key = "${file("~/.ssh/google_compute_engine")}"
        timeout = "45s"
      }
  }

但我不断收到以下错误。

Error applying plan:

1 error(s) occurred:

* ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

我还尝试在终端使用 ssh 直接登录 IP。

ssh -i ~/.ssh/google_compute_engine.pub 122.122.122.122

这工作得很好。所以我也在配置中尝试了这个,或者我认为在配置中会模仿这个。

provisioner "remote-exec" {
  inline = [
    "echo ${google_compute_instance.testing-elastic-1.network_interface.0.access_config.0.assigned_nat_ip}"]
    connection {
      type = "ssh"
      user = ""
      private_key = "${file("~/.ssh/google_compute_engine")}"
      timeout = "45s"
    }
}

又遇到一个错误。

申请计划时出错:

发生 1 个错误:

  • ssh:握手失败:ssh:无法验证,尝试的方法[无公钥],没有支持的方法

所以我尝试了这个。

provisioner "remote-exec" {
  inline = [
    "echo ${google_compute_instance.testing-elastic-1.network_interface.0.access_config.0.assigned_nat_ip}"]
    connection {
      type = "ssh"
      private_key = "${file("~/.ssh/google_compute_engine")}"
      timeout = "45s"
    }
}

最后,似乎什么都没有改变。我马上回来了这个错误消息。

Error applying plan:

1 error(s) occurred:

* ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

我不确定我还应该拥有或需要什么才能使 ssh 身份验证正常工作。

ssh google-cloud-platform google-compute-engine terraform
  • 1 1 个回答
  • 3359 Views

1 个回答

  • Voted
  1. Best Answer
    Sean
    2016-09-14T21:54:57+08:002016-09-14T21:54:57+08:00

    您的项目中可能有错误的sshKey设置。假设您的provisioneror附加了以下内容resource:

    resource "google_compute_instance" "my-host" {
      // ...
      connection {
        type        = "ssh"
        agent       = false
        user        = "${var.gce_ssh_user}"
        port        = "${var.gce_ssh_port}"
        timeout     = "5m"
        private_key = "${file("${var.gce_ssh_private_key_file}")}"
      }
      // ...
    }
    

    您应该能够验证项目的sshKey:

    $ gcloud compute project-info describe

    我的猜测是sshKey根据 GCE,项目的值设置部分没有很好地形成。如果您逐步执行以下操作,您可能会发现导致此问题的配置问题:

    $ gcloud compute project-info describe > project.yaml
    $ cat project.yaml| egrep 'ssh-' | awk '{print $1 " " $2 " " $3}' > existing_project_keys.pub
    $ awk -v USER="$USER" '{print USER ":" $1 " " $2 " " USER}' .ssh_id_rsa.pub > new_keys.pub
    $ cat existing_project_keys.pub >> new_keys.pub
    $ gcloud compute project-info add-metadata --metadata-from-file sshKeys=new_keys.pub
    

    (或者,这可能很简单,例如您的代理中加载了太多密钥,这就是我在connection上面禁用代理的原因)

    • 3

相关问题

  • 如何最好地设置 ssh 隧道以访问远程网络 (Linux)

  • SSH 和重定向

  • 通过 SSH 会话使用 NET USER 命令拒绝访问

  • SSH 服务器零日漏洞利用 - 保护自己的建议

  • ubuntu apt-get upgrade - 如何在 shell 中单击确定?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve