So, I’ve tried to build a new image exist snapshot from my ec2 instance with current keypair and having this issue.
Error message:
2021/08/31 15:09:22 packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64 plugin: 2021/08/31 15:09:22 [INFO] Attempting SSH connection to 13.212.160.196:22…
2021/08/31 15:09:22 packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64 plugin: 2021/08/31 15:09:22 [DEBUG] reconnecting to TCP connection for SSH
2021/08/31 15:09:22 packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64 plugin: 2021/08/31 15:09:22 [DEBUG] handshaking with SSH
2021/08/31 15:09:22 packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64 plugin: 2021/08/31 15:09:22 [DEBUG] SSH handshake err: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
2021/08/31 15:09:22 packer-plugin-amazon_v1.0.0_x5.0_darwin_amd64 plugin: 2021/08/31 15:09:22 [DEBUG] Detected authentication error. Increasing handshake attempts.
2021/08/31 15:09:22 ui error: ==> amazon-ebs.my-template: Error waiting for SSH: Packer experienced an authentication error when trying to connect via SSH. This can happen if your username/password are wrong. You may want to double-check your credentials as part of your debuggin
g process. original error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain
My template:
source "amazon-ebs" "my-template" {
profile = "${var.profile}"
region = "${var.region}"
ami_name = "${var.ami_name}-${local.timestamp}"
ami_virtualization_type = "hvm"
communicator = "ssh"
ssh_interface = "public_ip"
# pause_before_connecting = "5m"
ssh_username = "${var.ssh_username}"
ssh_keypair_name = "${var.ssh_keypair_name}"
ssh_private_key_file = "${var.ssh_private_key_file}"
ssh_agent_auth = true
ssh_timeout = "10m"
aws_polling {
delay_seconds = 60
max_attempts = 60
}
ebs_optimized = false
instance_type = "${var.instance_type}"
vpc_id = "${var.vpc_id}"
subnet_id = "${var.subnet_id}"
security_group_id = "${var.security_group_id}"
launch_block_device_mappings {
device_name = "/dev/sda1"
volume_size = "${var.root_volume_size_gb}"
volume_type = "${var.volume_type}"
delete_on_termination = true
}
source_ami_filter {
filters = {
name = "${var.filter_name}"
root-device-type = "ebs"
virtualization-type = "hvm"
}
most_recent = true
owners = ["${var.owner_id}"]
}
}
build {
sources = ["source.amazon-ebs.my-template"]
}
Command running:
packer build -var “ssh_private_key_file=/Users/movmac024/.ssh/mykey.pem” -var “profile=myaws” -var “region=ap-southeast-1” hcl/mytemplate.pkr.hcl
Fun fact, I can ssh to the instance when packer finish init but packer cannot and it stuck at ssh step.