packer build cannot ssh to aws instance

8.1k views Asked by At

The following configuration will spin up an instance but fails to connect it... but the same key, vpc-id, subnet id, and security group id works in test kitchen without issues.

{
  "variables": {
  "aws_access_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxx",
  "aws_secret_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
},
    "builders": [{
        "type": "amazon-ebs",
        "access_key": "{{user `aws_access_key`}}",
        "secret_key": "{{user `aws_secret_key`}}",
        "region": "us-east-1",
        "source_ami": "ami-146e2a7c",
        "instance_type": "t2.micro",
        "ssh_username": "ubuntu",
        "ami_name": "packer-example {{timestamp}}",
        "ssh_keypair_name": "xxx",
        "ssh_private_key_file": "xxx.pem",
        "vpc_id": "vpc-xxxxxxx",
        "subnet_id": "subnet-xxxxxxx",
        "security_group_id": "sg-xxxxxxx",
        "associate_public_ip_address": "true"

    }]
}

I get the following debug errors:

2016/12/17 20:10:50 packer: 2016/12/17 20:10:50 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [publickey none], no supported methods remain
2016/12/17 20:10:50 packer: 2016/12/17 20:10:50 [DEBUG] Detected authentication error. Increasing handshake attempts.
2016/12/17 20:10:57 packer: 2016/12/17 20:10:57 [INFO] Attempting SSH connection...
2016/12/17 20:10:57 packer: 2016/12/17 20:10:57 reconnecting to TCP connection for SSH
2016/12/17 20:10:57 packer: 2016/12/17 20:10:57 handshaking with SSH
2016/12/17 20:10:59 packer: 2016/12/17 20:10:59 handshake error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2016/12/17 20:10:59 packer: 2016/12/17 20:10:59 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2016/12/17 20:10:59 ui error: ==> amazon-ebs: Error waiting for SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2016/12/17 20:10:59 ui: ==> amazon-ebs: Terminating the source AWS instance...

Given that this works in test kitchen with no extra variables I'm wondering what I'm missing? Any ideas?

2

There are 2 answers

0
TyMac On

The problem was the wrong default username.

0
cyberPrivacy On

I solved it by not forgetting to add the public_key_pair (of the aws account) I had the same error message "amazon-ebs: Error waiting for SSH: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain" and problem was that I had forgotten to provide SSH_KEYPAIR_NAME to the dockerized Packer. After adding kaypair name, it works now!