Can not login the packer created ubuntu vm in Azure

0

I created an ubuntu linux image with packer. ( packer.io) Here is a slice from the .json

"os_type": "Linux",
    "image_publisher": "Canonical",
    "image_offer": "UbuntuServer",
    "image_sku": "16.04-LTS",

After I created a linux vm based on the vhd which created with packer I can not log-in with ssh. I always get a Public key error message. So, I have no public key because I don't know which shall I use??! Are ther any defaule public key inside? Or get it from somewhere?

GergA

Posted 2017-11-17T12:10:34.050

Reputation: 73

Answers

0

After I created a linux vm based on the vhd which created with packer I can not log-in with ssh.

By default, the new image build from Packer not have password and username.

Could you show me how do you create Azure VM with this VHD? Azure PowerShell or CLI 2.0?

Here a docs about how to use Packer to create Linux Virtual machine images in Azure, we can follow that steps to create Azure VM with packer image.

After the image build, we can use CLI 2.0 to create Azure VM, like this:

az vm create \
    --resource-group myResourceGroup \
    --name myVM \
    --image myPackerImage \
    --admin-username azureuser \
    --generate-ssh-keys

If we use this script to deploy Azure VM, this VM will generate a ssh key to your local PC, the key will store to .ssh.

By the way, if you can't find the key, we can reset public key via Azure portal. More information about reset SSH configuration, please refer to this link.

Jason Ye

Posted 2017-11-17T12:10:34.050

Reputation: 319

Hello Jason.Thank you for the suggestion.I would use this .vhd via Terraform. So I would create a vm via TF. – GergA – 2017-11-20T18:14:53.967

@GergA Could you please show your TF template, maybe we can find password there. By the way, if you can't find the password. we can via azure portal to reset the password. If my answer helps, please don't forget to accept it as an answer, thanks:) – Jason Ye – 2017-11-21T01:35:18.200

Ye. I will not forget to rate the answer :-). Here is my TF Template. https://pastebin.com/xerqUZq0 the only way is to inject my ssh key is if I star to work from Azure image like here: https://pastebin.com/Qcr4tAFX With packer-created image the os_profile option doesn't work

– GergA – 2017-11-21T09:16:13.733

@GergA I can't find anything about user account and password, by default, the packer create VHD, user name is packer, please try to use Azure portal to reset the password. – Jason Ye – 2017-11-21T09:22:04.017

I not 100% understand what you want. I need a vhd image what made by Packer and I can join to that with my username/password. I have no chance to reset the password on the created VM via Azure. Unfortunately the deplorvision phase in the end of Packer build remove the packer user. – GergA – 2017-11-21T12:06:21.430

@GergA we should add os_profile to TF json file,not packer. More information please refer to this link.

– Jason Ye – 2017-11-22T01:50:42.957

I know that. Please check my second pastebin: https://pastebin.com/Qcr4tAFX .Didn't worked

– GergA – 2017-11-22T08:52:05.523

@GergA Do you have the private key? when try ssh to this VM and specify this private key, does that work? – Jason Ye – 2017-11-22T08:54:25.973

with os_profile I get the following error: Status=400 Code="InvalidParameter" Message="Cannot specify user image overrides for a disk already defined in the specified image reference." – GergA – 2017-11-22T09:10:34.370

Let us continue this discussion in chat.

– Jason Ye – 2017-11-22T09:12:40.860

I start to make a managed_image with Packer and now I can create a VM with terraform from that. Thanks for Jason – GergA – 2017-11-22T15:26:15.777