我一直在通过与ssh的Terraform Provisioner连接问题进行斗争。 到目前为止,我已经尝试过以前的工作:
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
我也尝试在terminal上用ssh直接login到IP。
ssh -i ~/.ssh/google_compute_engine.pub 122.122.122.122
这工作得很好。 所以我也在configuration中试过这个,或者我认为会在configuration中模仿这个。
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个错误:
所以然后我尝试了这个。
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
我真的不知道还有什么我应该有或需要的SSHauthentication工作。
机会是你的项目中设置了错误的sshKey 。 假设您将以下内容附加到您的provisioner或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}")}" } // ... }
你应该能够validation项目的sshKey :
$ gcloud compute project-info describe
我的猜测是根据GCE,项目的sshKey值集合部分并不完整。 如果你通过如下的步骤,你可能会发现导致这个问题的configurationsnafu:
$ 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禁用了代理)