Ask Your Question
1

Defining default user-password for Ubuntu Cloud image

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

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

Comments

1

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

lorin gravatar imagelorin ( 2013-12-08 21:10:14 -0600 )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 -0600 )edit

4 answers

Sort by ยป oldest newest most voted
4

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

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

ubuntu:fcaKfNdsB

guestfish operation referance: http://docs.openstack.org/image-guide/content/ch_modifying_images.html

For other options in cloud.cfg file: http://bazaar.launchpad.net/~cloud-init-dev/cloud-init/trunk/view/head:/doc/examples/cloud-config.txt

edit flag offensive delete link more

Comments

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 -0600 )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 -0600 )edit
2

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

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:

/#cloud-config
password: mysecret
chpasswd: { expire: False }
ssh_pwauth: True

edit flag offensive delete link more

Comments

The answer is correct but the "/" at the beginning of the doesn't seem to work. See also https://ask.openstack.org/en/question/26817/how-to-prevent-cloud-init-from-disable-ssh-passwordauthentication/ (https://ask.openstack.org/en/question...)

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

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

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="">

#cloud-config

password: mysecret

chpasswd: { expire: False }

ssh_pwauth: True

EOF

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

Comments

Similiarly can we set password for root??

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

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

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!

<fs>shutdown

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

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

4 followers

Stats

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

Seen: 24,758 times

Last updated: Jun 15 '17