5

I`m creating a new image and everything is working. I would like to debug via ssh during the instance creation. A temp keypair is created and attached to the temp instance. My question is, can I get this keypair somewhere in order to debug it?

==> amazon-ebs: Prevalidating AMI Name...
    amazon-ebs: Found Image ID: ami-0866798422f5d546b
==> amazon-ebs: Creating temporary keypair: packer_5cc6c77d-494a-f185-b5b3-f9b59e62fd4e

Best,

Armando

1
  • This question has intrigued me quite a bit, so I went digging into the packer source code. It seems, as Mattieu wrote below, that the key is only written if you run in debug mode, or of course use your own. Else, it is kept in memory. (I only looked at the EBS builder) Jul 25 '19 at 7:07
7

First, make sure that packer runs in debug mode (packer build -debug ...), otherwise the temporary key will not be written to disk but will only be kept in memory.

packer will store the key in its working directory. In other words, look in the same directory from which you started the packer process.

If you use AWS, the file will be called ec2_amazon-ebs.pem. Assuming you are building an Ubuntu image, you should be able to login to the instance with this command:

ssh -i ec2_amazon-ebs.pem ubuntu@<ip>

(where <ip> can be found in the packer output or through the AWS console)

1
  • 1
    For me, it was ec2_centos.pem on packer v1.4.1, obviously, I was building a CentOS VM
    – vikas027
    Jun 18 '20 at 7:40
0

They are likely in the user's home folder, or the folder in which packer is running.

You can look at ~/.ssh, or you can specify you own keypair.

1
  • It is not. Packer only emits to file (in local dir) if running in debug.
    – Eddie
    Sep 22 '20 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.