Skip to content
Latchkey

Packer "Timeout waiting for SSH" in CI

Packer builds by connecting over SSH to run provisioners. If the security group blocks port 22, the key does not match, or the ssh_username is wrong, Packer waits and then times out.

What this error means

packer build prints "Waiting for SSH to become available..." repeatedly, then fails with "Timeout waiting for SSH" and tears down the instance.

packer
==> amazon-ebs.ubuntu: Waiting for SSH to become available...
==> amazon-ebs.ubuntu: Timeout waiting for SSH.
Build 'amazon-ebs.ubuntu' errored after 5 minutes: Timeout waiting for SSH.

Common causes

A security group that blocks inbound SSH

Port 22 is not open from the runner (or Packer temporary security group is not created), so the connection never establishes.

A wrong ssh_username for the AMI

Using root on Ubuntu (which needs ubuntu) or the wrong user for the image makes every SSH attempt fail.

How to fix it

Set the correct ssh_username and open SSH

  1. Set ssh_username to the AMI default (ubuntu, ec2-user, admin).
  2. Ensure a security group allows inbound TCP 22 from where Packer connects.
  3. Re-run the build and watch for a successful SSH connection.
build.pkr.hcl
source "amazon-ebs" "ubuntu" {
  ssh_username              = "ubuntu"
  temporary_security_group_source_cidrs = ["0.0.0.0/0"]
}

Route to a private instance

If the instance has no public IP, connect over a bastion or set ssh_interface = "session_manager" so Packer can reach it.

build.pkr.hcl
ssh_interface = "session_manager"

How to prevent it

  • Use the correct ssh_username for each source AMI.
  • Allow inbound SSH from the build network or use Session Manager.
  • Give private-subnet builds a bastion or SSM path.

Frequently asked questions

What causes ""Timeout waiting for SSH""?
Port 22 is not open from the runner (or Packer temporary security group is not created), so the connection never establishes.
How do I fix "Timeout waiting for SSH"?
Set the correct ssh_username and open SSH

Related guides

References

Run this faster and cheaper on Latchkey managed runners - self-healing included. Start free → 30-day trial · No credit card