大网数据广告活动
服务器运维问答

Using Packer with Google Cloud and getting an SSH connection issue w/ Debian Build

· 52CE 我爱测

Here's my Packer file. { "variables": { "account_json": "{{env `packer_account_json`}}" }, "builders": [ { "type": "googlecompute", "account_file": "{{user `account_json`}}", "project_id": "united-course-124523", "source_image": …

问题原文

原帖链接 · Adron · CC BY-SA 3.0

Here's my Packer file.

    {
    "variables": {
      "account_json": "{{env `packer_account_json`}}"
    },
    "builders": [
      {
        "type": "googlecompute",
        "account_file": "{{user `account_json`}}",
        "project_id": "united-course-124523",
        "source_image": "debian-8-jessie-v20160711",
        "zone": "us-central1-a",
        "instance_name": "hub-{{timestamp}}",
        "image_name": "hub-{{uuid}}",
        "image_description": "Elasticsearch 2.3.4."
      }
    ],
    "provisioners": [
      {
        "type": "shell",
        "inline": [
          "sleep 20",
          "echo \"slept for 20 seconds.\""
        ]
      },
      {
        "type": "file",
        "source": "../scripts/install-elastic.sh",
        "destination": "../scripts/install-elastic.sh"
      },
      {
        "type": "shell",
        "script": "../scripts/install-elastic.sh",
        "pause_before": "3s"
      }
    ]
  }

I run this and then get an SSH error as shown (with executing command)

$ packer build elastic-2.3.4.json
googlecompute output will be in this color.

==> googlecompute: Checking image does not exist...
==> googlecompute: Creating temporary SSH key for instance...
==> googlecompute: Creating instance...
    googlecompute: Loading zone: us-central1-a
    googlecompute: Loading image: debian-8-jessie-v20160711 in project united-course-124523
    googlecompute: Loading machine type: n1-standard-1
    googlecompute: Loading network: default
    googlecompute: Requesting instance creation...
    googlecompute: Waiting for creation operation to complete...
    googlecompute: Instance has been created!
==> googlecompute: Waiting for the instance to become running...
    googlecompute: IP: 104.197.225.237
==> googlecompute: Waiting for SSH to become available...
==> googlecompute: Error waiting for SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
==> googlecompute: Deleting instance...
    googlecompute: Instance has been deleted!
==> googlecompute: Deleting disk...
    googlecompute: Disk has been deleted!
Build 'googlecompute' errored: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

I've been looking at the Packer docs here https://www.packer.io/docs/provisioners/file.html regarding the file upload, and don't see anything about making an SSH connection, and also have been checking out the docs on remote ssh here https://www.packer.io/docs/provisioners/shell.html but still don't see what the issue is exactly that is causing the image to error out with the sh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain message.

I also added the communicator key and value to ssh per @tekjava suggested and still the same error. My builder looked like this after the addition.

{
  "type": "googlecompute",
  "account_file": "{{user `account_json`}}",
  "project_id": "united-course-124523",
  "source_image": "debian-8-jessie-v20160711",
  "zone": "us-central1-a",
  "instance_name": "{{user `instance_name`}}",
  "image_name": "elastic-{{uuid}}",
  "image_description": "Elasticsearch 2.3.4.",
  "communicator": "ssh"
}

已采纳解答

原帖链接 · Matthias Winkelmann · CC BY-SA 3.0

There are some images on Google Cloud Engine that disable root ssh access by default. Centos, Debian, and the new Container-VM image seem to be among those. It seems to be solved by specifying a username to use:

"ssh_username": "anythingyoulike"

...which will then be created by Packer during the build.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2016-07-27)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。