Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.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
Google cloud platform 地形:can';t使用生成的SSH密钥在计算引擎VM上执行远程执行_Google Cloud Platform_Terraform_Ssh Keys_Terraform Provider Gcp - Fatal编程技术网

Google cloud platform 地形:can';t使用生成的SSH密钥在计算引擎VM上执行远程执行

Google cloud platform 地形:can';t使用生成的SSH密钥在计算引擎VM上执行远程执行,google-cloud-platform,terraform,ssh-keys,terraform-provider-gcp,Google Cloud Platform,Terraform,Ssh Keys,Terraform Provider Gcp,我正在尝试使用Terraform的ssh密钥在新配置的Google云平台计算引擎VM上远程执行一些命令。这是我的密码: resource "tls_private_key" "ssh-key" { algorithm = "RSA" rsa_bits = 4096 } resource "google_compute_instance" "static-content" { # ... metadata { sshKeys = "root:${tls_privat

我正在尝试使用Terraform的ssh密钥在新配置的Google云平台计算引擎VM上远程执行一些命令。这是我的密码:

resource "tls_private_key" "ssh-key" {
  algorithm = "RSA"
  rsa_bits  = 4096
}

resource "google_compute_instance" "static-content" {

  # ...

  metadata {
    sshKeys = "root:${tls_private_key.ssh-key.public_key_openssh}"
  }

  connection {
    type = "ssh"
    user = "root"
    private_key = "${tls_private_key.ssh-key.private_key_pem}"
  }

  provisioner "remote-exec" {
    inline = [
      "curl -L https://github.com/aelsabbahy/goss/releases/download/v0.3.6/goss-linux-amd64 -o ~/goss",
      "chmod +x ~/goss",
      "~/goss -g ~/gossfile.yml validate",
    ]
  }

}
我在Terraform应用中得到的输出是

google_compute_instance.static-content: Still creating... (2m10s elapsed)
google_compute_instance.static-content (remote-exec): Connecting to remote host via SSH...
google_compute_instance.static-content (remote-exec):   Host: 35.198.166.131
google_compute_instance.static-content (remote-exec):   User: root
google_compute_instance.static-content (remote-exec):   Password: false
google_compute_instance.static-content (remote-exec):   Private key: true
google_compute_instance.static-content (remote-exec):   SSH Agent: false
google_compute_instance.static-content (remote-exec):   Checking Host Key: false

因此,ssh密钥似乎没有正确地传播到VM。有什么提示说明为什么这不起作用吗?

看起来你只是用另一种方式尝试了一下,下面的代码对我有用

provisioner "remote-exec" {
connection {
type = "ssh"
port = 22
user = "username"
agent = "false"
private_key = "${file("/path/to/your/pem_file")}"
}
 inline = [
 "your command goes here",
  ]
}
}

它是一个生成的SSH密钥(如),而不是用户文件系统上的SSH密钥。问题似乎是试图以
root
身份ssh到计算机中,这似乎是不允许的。当我切换到
gcp
用户并使用
sudo
运行命令时,一切都按预期进行。无论如何谢谢你!