Generate User Password in Ubuntu Cloud Image

12/05/2014 // 0 Comments

When you boot standard Ubuntu Cloud image in the Openstack, no password or user generated in the image by default. You can configure your Ubuntu Cloud image to set a static password or generate a password in the first boot of the image. You need to configure metadata service in the Openstack in order to use this. I suggest you to do this jobs in your Glance server, your images will be saved to this server anyway.   Firstly, download your Ubuntu cloud image from this link: Install guestfish in your server. This server probably will be your Glance image server. :

In order to edit the image file open it with guestfish:

Then, start your image file:

Find the image local disk:

Mount the image disk to guestfish root:

Now, you can edit /etc/cloud/cloud.cfg file by using vi editor. I wanted to set random password for ubuntu user, so I added these lines to the cloud.cfg file: for 12.04 LTS images, you can set your static password or randomize:

for 14.04 LTS images I have not tried to randomize the password yet, but static password can be set with this commands:

Be careful to comment out the “lock_passwd: True” raw in the cloud.cfg file. It will not allow you to login if you do not remove it. Save cloud.cfg file and exit from guestfish. That’s it! Import this modified image to Openstack and Ubuntu password will be randomly created or static password will be set . If you randomized the password it will be printed to Console-log of the instance:

guestfish operation referance: Here are some examples in cloud.cfg file: