【问题标题】:terraform ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remainterraform ssh:握手失败:ssh:无法验证,尝试的方法 [none publickey],没有支持的方法
【发布时间】:2020-08-04 00:06:31
【问题描述】:

我不知道它试图通过 SSH 连接到哪里?进入新部署的资源?

如何更详细地诊断此错误?

Error: Error applying plan:

1 error occurred:
    * module.deploy_nixos.null_resource.deploy_nixos: timeout - last error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
data "google_compute_network" "default" {
  name = "default"
}

resource "google_compute_firewall" "deploy-nixos" {
  name    = "deploy-nixos"
  network = "${data.google_compute_network.default.name}"

  allow {
    protocol = "icmp"
  }

  // Allow SSH access
  allow {
    protocol = "tcp"
    ports    = ["22", "80", "443"]
  }

  source_tags = ["nixos"]
}

resource "google_compute_instance" "deploy-nixos" {
  name         = "deploy-nixos-example"
  machine_type = "g1-small"
  zone         = "europe-west2-a"
  # region      = "eu-west2"

  // Bind the firewall rules
  tags = ["nixos"]

  boot_disk {
    initialize_params {
      // Start with an image the deployer can SSH into
      image = "${module.nixos_image_custom.self_link}"
      size  = "25"
    }
  }

  network_interface {
    network = "default"

    // Give it a public IP
    access_config {}
  }

  lifecycle {
    // No need to re-deploy the machine if the image changed
    // NixOS is already immutable
    ignore_changes = ["boot_disk"]
  }
}

module "deploy_nixos" {
  source = "../../deploy_nixos"

  // Deploy the given NixOS configuration. In this case it's the same as the
  // original image. So if the configuration is changed later it will be
  // deployed here.
  nixos_config = "${path.module}/image_nixos_custom.nix"

  target_user = "root"
  target_host = "${google_compute_instance.deploy-nixos.network_interface.0.access_config.0.nat_ip}"

  triggers = {
    // Also re-deploy whenever the VM is re-created
    instance_id = "${google_compute_instance.deploy-nixos.id}"
  }
}

带调试输出:

module.deploy_nixos.null_resource.deploy_nixos: Creating...
  triggers.%:                 "" => "3"
  triggers.deploy_nixos_drv:  "" => "/nix/store/0dmz6dhqbk1g6ni3b92l95s377zbikaz-nixos-system-unnamed-19.03.172837.6c3826d1c93.drv"
  triggers.deploy_nixos_keys: "" => "44136fa355b3678a1146ad16f7e8649e94fb4fc21fe77e8310c060f61caaff8a"
  triggers.instance_id:       "" => "deploy-nixos-example"
module.deploy_nixos.null_resource.deploy_nixos: Provisioning with 'file'...
2019-06-08T22:31:00.030Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [DEBUG] connecting to TCP connection for SSH
2019-06-08T22:31:00.041Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [DEBUG] handshaking with SSH
2019-06-08T22:31:00.119Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06/08 22:31:00 [WARN] ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2019-06-08T22:31:00.119Z [DEBUG] plugin.terraform: file-provisioner (internal) 2019/06

【问题讨论】:

  • 我猜 terraform 正在尝试使用 target_usertarget_host 连接到 deploy_nixos 模块中声明的 deploy_nixos。问题是它将使用哪个 ssh 密钥?看看下面@qudongfang 的回答。

标签: terraform


【解决方案1】:

检查模块的来源(source =“../../deploy_nixos”)可能在那里定义了null_resource(这里的问题中没有显示)。您可能在那里使用了 terraform remote_exec 或文件配置器,您需要检查其中的连接属性。

Terraform 连接属性示例如下所示

provisioner "file" {
  source      = "conf/myapp.conf"
  destination = "/etc/myapp.conf"

  connection {
    type     = "ssh"
    user     = "root"
    password = "${var.root_password}"
  }
}

更多详情请查看:https://www.terraform.io/docs/provisioners/connection.html

【讨论】:

    【解决方案2】:

    确保您的 ssh 密钥已添加。

       ssh-add ~/.ssh/id_rsa 
    

    【讨论】:

      猜你喜欢
      • 2021-02-22
      • 2022-11-10
      • 2022-06-21
      • 2016-05-26
      • 1970-01-01
      • 2021-02-25
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多