39

I am trying to build a cloud infrastructure using VM's

In the Openstack manuals, it is mentioned that the images in this link contain, Openstack pre-installed.

I downloaded the trusty-server-cloudimg-amd64-disk1.img file and I loaded it using KVM. I instantiated a Virtual Machine using this image but I am not able to login (using the console) or ssh into it.

I do not know the default username and password of that OS.

Also (a different question), I would like to build a Cloud using the 2 Virtual Machines, is it possible to use the same image?

Athafoud
  • 2,898
  • 3
  • 40
  • 58
Sherwin Varghese
  • 481
  • 1
  • 5
  • 7

7 Answers7

25

18.04 setup step-by-step with cloud-localds

In short you need on the host:

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 \
-m 1G
...

and now you can login with:

  • username: ubuntu
  • password: asdfqwer

Here I describe a full minimal detailed working QEMU example: https://askubuntu.com/questions/281763/is-there-any-prebuilt-qemu-ubuntu-image32bit-online/1081171#1081171

Tested on an Ubuntu 18.04 host.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
  • 2
    Still unable to login inside ubuntu 20.04.3 . Says Login incorrect. Any idea why so? – watney Aug 26 '21 at 10:04
  • 1
    @watney I did a quick try on Ubuntu 21.04 and it didn't immediately work. Let me know if you find something else. Those Ubuntu cloud images are too flaky. – Ciro Santilli OurBigBook.com Aug 29 '21 at 09:04
  • 1
    Same steps verified to work for ubuntu 20.04 – slogan621 Feb 12 '22 at 17:38
  • On 20.04 ssh login works, console login doesn't. Still can't figure this out. – Rino Bino Sep 07 '22 at 23:36
  • 1
    Works on 22.04 (jammy-server-cloudimg-amd64.img). I prefer `-hda` and `-hda` option: `qemu-system-x86_64 -hda ubuntu-18.04-server-cloudimg-amd64.img -hdb user-data.img -m 1G -enable-kvm`. I noticed that the password is saved to the Ubuntu disk; so we can't change "password" in `user-data` after once booted. – wataash Oct 03 '22 at 03:23
  • cloud-image-utils doesn't exist in my distribution, a download of user-data.img would've been appreciated. – secondperson Oct 27 '22 at 18:01
21

How about this:

$ virt-customize -a bionic-server-cloudimg-amd64.img --root-password password:coolpass
rofrol
  • 14,438
  • 7
  • 79
  • 77
8

The default username for ubuntu image is ubuntu.
There is not a default password, and you can not ssh to the machine using username / password or connect through the VNC console. You have to use public / private key authentication method with ssh. Also sudo elevation for ubuntu account is passwordless.

After accessing for the first time your virtual machine, you can change those settings and enable username / password authentication for ssh.

Regarding your second question,
Yes, you can use the same image for multiple virtual machine.

Athafoud
  • 2,898
  • 3
  • 40
  • 58
  • 2
    how to use public/private key auth method? If I use ssh-copy-id -p 2222 ubuntu@localhost where 2222 is the redirected ssh port I get: Permission denied (public key). – hlitz Sep 19 '16 at 17:32
  • @hlitz You have to upload your public while you are creating the VM. If you are using the UI, the is a step where the system prompts you for the public key. If you are using the console and the API to create the VM, there is a command (which I cannot recall right now) that you can use and pass your key. – Athafoud Sep 20 '16 at 06:23
  • 16
    I've tried xenial-server-cloudimg-arm64-uefi1.img from http://cloud-images.ubuntu.com/xenial/20161029/ : login "ubuntu" doesn't work, it then requests the password, I tried empty - and it says "Login incorrect". – Serge Rogatch Nov 01 '16 at 20:33
  • @SergeRogatch Quoting a part of my answer `There is not a default password, and you can not ssh to the machine using username / password or connect through the VNC console. You have to use public / private key authentication method with ssh. ` – Athafoud Nov 01 '16 at 21:06
  • 2
    @Athafoud, I don't think I'm using SSH. I just booted the VM in QEmu and used the terminal where it started. – Serge Rogatch Nov 01 '16 at 21:21
  • @SergeRogatch that's exactly the case, you can not use the terminal. Your only choice is to configure and use ssh. – Athafoud Nov 01 '16 at 22:11
  • @Athafoud , shall I post a separate question on how to do this? – Serge Rogatch Nov 02 '16 at 13:32
  • 1
    @SergeRogatch Yes, I think that it will be better that way. – Athafoud Nov 02 '16 at 13:51
  • @SergeRogatch, did you post that question? Can you link to it? – meshy Apr 05 '18 at 22:38
  • @meshy, no, I can't find such question among my posted questions, and now I don't remember how I solved the issue, sorry. – Serge Rogatch Apr 06 '18 at 07:51
6

Mounting the image and then using chpasswd inside the chroot was the easiest solution for me:

modprobe nbd max_part=8 && qemu-nbd -c /dev/nbd0 image.raw && mkdir a && mount /dev/nbd0p1 a
chroot a sh -c "echo 'root:password' | chpasswd"
umount ./a && rmdir a && qemu-nbd -d /dev/nbd0
gucki
  • 4,582
  • 7
  • 44
  • 56
1

The following code could be used to make the Ubuntu cloudimg usable on a Debian 7.2 (wheezy) machine:

apt-get install pwgen
apt-get install genisoimage
git clone -b master https://git.launchpad.net/cloud-utils

printf "#cloud-config\n" > user-data
printf "password: `pwgen 8 1`\nchpasswd: { expire: False }\nssh_pwauth: True\n" >> user-data
./cloud-utils/bin/cloud-localds user-data.img user-data

Subsequently, you'd start the image like this, from within a tmux window to make sure it'll keep running even if you logout:

kvm -m 2048 -smp 2 -hda ubuntu-18.10-server-cloudimg-amd64.img -hdb user-data.img -net nic -net user,hostfwd=tcp::1810-:22 -nographic

You can then login into the machine as user ubuntu and the password as generated within the user-data file. The login can be either through the serial console printed by kvm (which would normally be pretty slow, even if you have an ssh connection on top of it), or through ssh with ssh ubuntu@localhost -p1810. The user ubuntu gets passwordless sudo access as root by default.


P.S. I've also tried playing with adding the ssh-authorized-keys, but cloud-config format seems very fragile, and at top level it's just ignored, whereas at a users: level as below, the whole ubuntu user seems to break (at least the password part of it). Here's the code to get the keys into a format that's potentially legible for cloud-config:

printf "users:\n  - name: ubuntu\n    ssh-authorized-keys:\n" >> user-data
cat ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys | sed 's/^/      - /g' >> user-data

(Note that the password, apparently, may not be a valid field for the users specification, as it has a passwd hash instead, so, the whole thing breaks the prior code, because now the user ubuntu gets created without a password.)

cnst
  • 25,870
  • 6
  • 90
  • 122
1

virt-customize just fail in my case, here I'm using virt-sysprep set the password ok.

cp ubuntu-21.04-server-cloudimg-amd64.img wen3.img
chown qemu:qemu wen3.img

virt-sysprep --root-password password:1 --uninstall cloud-init --selinux-relabel -a wen3.img --network --hostname=wen3

virt-install \
    --import  \
    --name wen3 \
    --ram=16384 \
    --vcpus=16 \
    --accelerate \
    --network network:default,model=virtio \
    --mac 02:ca:fe:fa:ce:33 \
    --debug \
    --wait 0 \
  --console pty \
    --disk path=/var/lib/libvirt/images/wen3.img,bus=virtio,size=100 \
    --os-variant centos7.0
Chinglin Wen
  • 149
  • 1
  • 3
0

Here are some details on how to log into a new Ubuntu instance for the first time, to complement @Athafoud's answer.

In the OpenStack GUI, you manage your public/private keys under Project > Compute > Access & Security. Create an SSH key (e.g. by using ssh-keygen under Linux or macOS) and add it to the OpenStack keys by clicking on "Import Key Pair". (Or you can "Create a Key Pair" from within the OpenStack GUI and then export the keys to your workstation.)

When you create the new instance (VM), you have to specify this key as the "keypair" you will use to log in for the first time.

Once your new instance is up and running, connect to it via SSH as follows:

ssh -i <keyfile> ubuntu@<instance>

where <keyfile> is the name of the SSH key you associated with the instance, and <instance> is the hostname or IP address of the instance. This command logs you into the ubuntu account on the instance without asking for a password.

The ubuntu user has sudo privileges, so you can become root by typing sudo -i after login, and manage the VM as you please :-).

András Aszódi
  • 8,948
  • 5
  • 48
  • 51