Actually you can't copy the pub key if you can't log in. You can use boot_command to login on the console and add the pubkey if you have any login enabled.
There have been a recent discussion to automate some of this in https://github.com/hashicorp/packer/issues/7225 VirtualBox is not a "cloud" so cloud-init will not just work (there is no API to handle the pubkey with), but you could prepare a config-drive before running Packer, for more info see the issue above. On Fri, Feb 1, 2019 at 9:01 AM Virt Man <[email protected]> wrote: > You can use file directive to copy the ssh key while building the image. > https://packer.io/docs/builders/file.html > > > On Fri, Feb 1, 2019 at 6:22 AM Simar Arora <[email protected]> wrote: > >> Hi, >> >> I am trying to provision Ubuntu cloud image in my virtual box(OVA >> format), the cloud image does not come with default login credentials and >> needs ssh key pair to be inserted in VM. After some research, I found that >> it can be done with cloud-init >> <https://askubuntu.com/questions/797462/problem-with-ubuntu-cloud-image-16-04-on-virtualbox>, >> wondering if this can be done with Packer as well? >> >> >> { >> "builders":[{ >> >> "type": "virtualbox-ovf", >> "source_path": "ubuntu-bionic-18.04-cloudimg.ovf", >> "ssh_private_key_file": "~/development/packer_scripts/ssh/id_rsa", >> "shutdown_command": "echo 'packer' | sudo -S shutdown -P now", >> "vboxmanage": [ >> ["modifyvm", "{{.Name}}", "--memory", "1024"], >> ["modifyvm", "{{.Name}}", "--cpus", "2"], >> [ "modifyvm", "{{.Name}}", "--uart1", "0x3F8", "4" ] >> ], >> "boot_command":[ >> "<esc><wait>", >> "<esc><wait>", >> "<esc><wait>" >> ] >> } >> ] >> } >> >> >> -- >> This mailing list is governed under the HashiCorp Community Guidelines - >> https://www.hashicorp.com/community-guidelines.html. Behavior in >> violation of those guidelines may result in your removal from this mailing >> list. >> >> GitHub Issues: https://github.com/mitchellh/packer/issues >> IRC: #packer-tool on Freenode >> --- >> You received this message because you are subscribed to the Google Groups >> "Packer" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/packer-tool/35c47410-efb7-4b48-9af9-edc754adbc16%40googlegroups.com >> <https://groups.google.com/d/msgid/packer-tool/35c47410-efb7-4b48-9af9-edc754adbc16%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > -- > This mailing list is governed under the HashiCorp Community Guidelines - > https://www.hashicorp.com/community-guidelines.html. Behavior in > violation of those guidelines may result in your removal from this mailing > list. > > GitHub Issues: https://github.com/mitchellh/packer/issues > IRC: #packer-tool on Freenode > --- > You received this message because you are subscribed to the Google Groups > "Packer" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To view this discussion on the web visit > https://groups.google.com/d/msgid/packer-tool/CANu2A1A%3D6X5nVXZJ%3D5MKW6o4H4csJOOp9kLp3ZaioaH4x%3DZCsQ%40mail.gmail.com > <https://groups.google.com/d/msgid/packer-tool/CANu2A1A%3D6X5nVXZJ%3D5MKW6o4H4csJOOp9kLp3ZaioaH4x%3DZCsQ%40mail.gmail.com?utm_medium=email&utm_source=footer> > . > For more options, visit https://groups.google.com/d/optout. > -- This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list. GitHub Issues: https://github.com/mitchellh/packer/issues IRC: #packer-tool on Freenode --- You received this message because you are subscribed to the Google Groups "Packer" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/packer-tool/CALz9Rt8%2BRuZdmhQH2JdT%3DYPQbt6Z2asx5PmN0AdOgFKmTDJF_Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
