2

I'm running an OpenStack cloud with a very particular network configuration, that makes it impossible for an instance to communicate with anything in the outside world until after I login into it and set several config files.

As a result of this, I cannot log in to instances using SSH keys. Is there a way to set a default password on an Ubuntu 12.04 (has to be 12.04) cloud image so I can log in to it directly from the Horizon console? I tried using the procedure outlined at https://ask.openstack.org/en/question/5531/defining-default-user-password-for-ubuntu-cloud-image/ but it did not work on Ubuntu 12.04... it did work on 14.04 though.

meshy
  • 125
  • 8

3 Answers3

7

18.04 setup step-by-step

In short you need:

sudo apt-get install cloud-image-utils

cat >user-data <<EOF
#cloud-config
password: asdfqwer
chpasswd: { expire: False }
ssh_pwauth: True
EOF

cloud-localds user-data.img user-data

# user-data.img MUST come after the rootfs. 
qemu-system-x86_64 \
-drive file=ubuntu-18.04-server-cloudimg-amd64.img,format=qcow2 \
-drive file=user-data.img,format=raw
...

and now you can login with:

  • username: ubuntu
  • password: asdfqwer

Here I describe a full minimal detailed working QEMU example: Is there any prebuilt QEMU Ubuntu image(32bit) online?

1

You can first create a Virtual Machine (VM) image from virtualbox or vmware which already has a key pair. as you can control your virtualbox or vmware freely, you can get the key pair from the virtual host.

  1. then import the keypair into your openstack.

  2. upload this virtual machine image

  3. create a instance(A) from this image

  4. create a instance(B) from the cloud image with the keypair(uploaded from step 1) injected

  5. open the console(in horizon) of instance A, now you can connect the instance B from A, because B has injected the public key from A

  6. after logged in, you can set up the environment for instance B & change the configuration

Anon
  • 12,063
  • 23
  • 70
  • 124
hgfeaon
  • 11
0

your image is:focal-server-cloudimg-amd64.img

rm -f vm_0001-focal-server-cloudimg-amd64.qcow2
qemu-img create -f qcow2 -F qcow2 -b focal-server-cloudimg-amd64.img  vm_0001-focal-server-cloudimg-amd64.qcow2 20G
qemu-img info vm_0001-focal-server-cloudimg-amd64.qcow2
VM_NAME="ubuntu-20-cloud-image"
USERNAME="programster"
PASSWORD="thisok"
echo "#cloud-config
system_info:
  default_user:
    name: $USERNAME
    home: /home/$USERNAME

password: $PASSWORD chpasswd: { expire: False } hostname: $VM_NAME

configure sshd to allow users logging in using password

rather than just keys

ssh_pwauth: True " | sudo tee user-data cloud-localds ./cidata.iso user-data qemu-system-x86_64 -m 2048 -smp 4 -hda ./vm_0001-focal-server-cloudimg-amd64.qcow2
-cdrom ./cidata.iso -device e1000,netdev=net0 -netdev user,id=net0,hostfwd=tcp::5555-:22 -nographic

jamlee
  • 101