Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Terraform ssh:握手失败:ssh:无法进行身份验证,尝试的方法[无公钥],没有支持的方法保留_Terraform_Terraform Provider Aws_Terraform0.12+ - Fatal编程技术网

Terraform ssh:握手失败:ssh:无法进行身份验证,尝试的方法[无公钥],没有支持的方法保留

Terraform ssh:握手失败:ssh:无法进行身份验证,尝试的方法[无公钥],没有支持的方法保留,terraform,terraform-provider-aws,terraform0.12+,Terraform,Terraform Provider Aws,Terraform0.12+,我试图使用Terraform provisionerremote exec在ec2实例上安装Nginx,但我一直遇到这个错误 ssh:握手失败:ssh:无法进行身份验证,尝试的方法[无公钥],没有支持的方法保留 这就是我的代码的样子 resource "aws_instance" "nginx" { ami = data.aws_ami.aws-linux.id instance_type =

我试图使用Terraform provisioner
remote exec在ec2实例上安装Nginx,但我一直遇到这个错误

ssh:握手失败:ssh:无法进行身份验证,尝试的方法[无公钥],没有支持的方法保留

这就是我的代码的样子

resource "aws_instance" "nginx" {
  ami                    = data.aws_ami.aws-linux.id
  instance_type          = "t2.micro"
  key_name               = var.key_name
  vpc_security_group_ids = [aws_security_group.allow_ssh.id]

  connection {
    type        = "ssh"
    host        = self.public_ip
    user        = "ec2-user"
    private_key = file(var.private_key_path)
    

  }

  provisioner "remote-exec" {
    inline = [
      "sudo yum install nginx -y",
      "sudo service nginx start"
    ]
  }
}
安全组规则设置为允许从任何位置进行ssh。 我可以用ssh从我的本地机器进入这个盒子


我不确定我是否错过了这里很明显的。我尝试过Terraform的更新版本,但问题是相同的。

如果您的EC2实例使用AMI作为使用的操作系统(大多数Linux发行版的默认映像都使用AMI),那么您可以使用
user\u data
参数将脚本传递到cloud init,从而完全避免Terraform通过SSH登录:

resource "aws_instance" "nginx" {
  ami                    = data.aws_ami.aws-linux.id
  instance_type          = "t2.micro"
  key_name               = var.key_name
  vpc_security_group_ids = [aws_security_group.allow_ssh.id]

  user_data = <<-EOT
    yum install nginx -y
    service nginx start
  EOT
}
资源“aws\u实例”“nginx”{
ami=data.aws\u ami.aws-linux.id
实例_type=“t2.micro”
key\u name=var.key\u name
vpc_security_group_id=[aws_security_group.allow_ssh.id]

user\u data=您正在为
var.key\u name
var.private\u key\u path
传递哪些值?我正在传递相同的.pem密钥对文件。非常感谢Martin。我将查看文档。