Ask Your Question

Defining default user-password for Ubuntu Cloud image

asked 2013-09-29 04:59:49 -0500

Y Sertdemir gravatar image

Hello, I am using Grizzly on Ubuntu 12.04 servers. I deployed Ubuntu 12.04 cloud image to Openstack. It works fine, but when a user creates an instance from this image, he-she will not be able to login immediately because of no user-password. I want to create an Ubuntu Cloud image which prints username-password to the instance log; or uses a static user-password at the first creation of the instance. I have no experience with image creating, is there a simple way to do it, or do I need to build my own image with static password?

edit retag flag offensive close merge delete



Can you explain why you don't want to use ssh keys for your situation?

lorin gravatar imagelorin ( 2013-12-08 21:10:14 -0500 )edit

Because I want that users of Openstack are able to create their instances without entering console of the nodes. I found the solution below anyway.

Y Sertdemir gravatar imageY Sertdemir ( 2013-12-09 01:27:39 -0500 )edit

4 answers

Sort by ยป oldest newest most voted

answered 2013-09-29 06:28:50 -0500

Y Sertdemir gravatar image

I found how:

Firstly install guestfish:

# apt-get install guestfish

In order to edit the img file:

# guestfish --rw -a precise-server-cloudimg-amd64-disk1.img

Then, start your image file:

><fs> run

Find the image local disk:

><fs> list-filesystems
/dev/vda1: ext4

Mount the image disk to guestfish root:

><fs> mount /dev/vg_centosbase/lv_root /

Now, you can edit /etc/cloud/cloud.cfg file in order to load whatever you want when instance created. I wanted to set user password for ubuntu user, so I added these lines to the cloud.cfg file:

password: RANDOM
chpasswd: { expire: False }
ssh_pwauth: True

Save and exit from guestfish. That's it! :)

You can import this modified image to Openstack and Ubuntu password will be randomly created and printed to Console-log of the instance:

Generation complete.
Set the following passwords


guestfish operation referance:

For other options in cloud.cfg file:

edit flag offensive delete link more


This method doesn't seem to work. The password is not printed to the log at all.

1overcosc gravatar image1overcosc ( 2014-08-05 15:50:05 -0500 )edit

Unfortunately, it was working with Grizzly version. At Havana, I guess they updated the cloud-config package and there is no password generation.

Y Sertdemir gravatar imageY Sertdemir ( 2014-09-29 08:11:55 -0500 )edit

answered 2013-12-08 17:21:45 -0500

dudeofthestick gravatar image

Maybe its too late, but you can pass as user data the following cloud-init configuration to use the ubuntu user from the console and from ssh:

password: mysecret
chpasswd: { expire: False }
ssh_pwauth: True

edit flag offensive delete link more


The answer is correct but the "/" at the beginning of the doesn't seem to work. See also (

MCo gravatar imageMCo ( 2014-08-27 08:07:06 -0500 )edit

answered 2016-03-14 00:22:10 -0500

Suresh Dharavath gravatar image

Adding a bit more to dudeofthestick's answer. Yes you should remove the "/" from there( while publishing the answer, having # in front of any line makes it bold so to suppress it he used the / infront )

cat > my-user-data <<eof< p="">


password: mysecret

chpasswd: { expire: False }

ssh_pwauth: True


Once that is done launch the VM using

kvm -net nic -net user -hda disk.qcow2 -hdb my-user-data -m 512

Now login with myscreat as password and create your own user( as to login with default user all the time, we have to seed the mysecret all the time ) and set the password for that user. Now every time you login you can login through the user you have added.

edit flag offensive delete link more


Similiarly can we set password for root??

udayutkarsh gravatar imageudayutkarsh ( 2017-02-21 02:16:36 -0500 )edit

answered 2017-06-15 22:22:29 -0500

guestfish -a cloud-img.img (CentOS or Ubuntu, doesn't matter which one) <fs>run <fs>list-filesystems <fs>mount /dev/blah / <fs>vi /etc/passwd

Change root:x:... in the first line to root::...and write to disk with wq!


Add .img to virt-manager, creating new instance. Now you can log in with no password as root.

edit flag offensive delete link more

Get to know Ask OpenStack

Resources for moderators

Question Tools



Asked: 2013-09-29 04:59:49 -0500

Seen: 29,928 times

Last updated: Jun 15 '17