Password in cloud-init doesn't seem to work, default one does though (for ubuntu)

So I have been having problems getting the password set for the initial account. If I use the string in Running virtual machines with LXD 4.0

passwd: "\$6\$s.wXDkoGmU5md\$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"

However I want to change the password. I’ve tried a number of ways:

Method 1

 python3 -c 'import crypt, getpass; print(crypt.crypt(getpass.getpass()))'

Method 2

echo "pass" | mkpasswd --method=SHA-512 --stdin

Neither seems to work when I copy that string into the pass field. Here is how I created the VM and started it:

sudo lxc init ubuntu:20.04 vm1 --vm -c security.secureboot=false
(
cat << EOF
#cloud-config
apt_mirror: http://us.archive.ubuntu.com/ubuntu/
ssh_pwauth: yes
users:
  - name: user
    passwd: "$6$jkaSxludpbR9Iy8U$dxlQUZeVTuavn5RIoGhDLwiHcLRYrd2gso3XjYEKRpSUkObRwabwb7f7BBl1JhZ3bwBEy2er3Euw4pGyWq4mD/"
    lock_passwd: false
    groups: lxd
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
EOF
) | sudo lxc config set vm1 user.user-data -
sudo lxc config device add vm1 config disk source=cloud-init:config
sudo lxc start vm1
sudo lxc console vm1

I also created an Archlinux VM, and that also kept giving me “incorrect password”.

sudo lxc init images:archlinux/current/amd64 vm2 --vm -c security.secureboot=false
(
cat << EOF
#cloud-config
ssh_pwauth: yes
users:
  - name: user
    passwd: "\$6\$s.wXDkoGmU5md\$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"
    lock_passwd: false
    groups: lxd
    shell: /bin/bash
    sudo: ALL=(ALL) NOPASSWD:ALL
EOF
) | sudo lxc config set vm2 user.user-data -
sudo lxc config device add vm2 config disk source=cloud-init:config
sudo lxc start vm2
sudo lxc console vm2

I just want to create an Ubuntu and Archlinux VM. I noticed with Archlinux there doesn’t appear to be a cloud version when doing lxc image list images: cloud so that will mean I guess I have to install lxd-agent manually.

I made a lxd profile for cloud-init:

config:
  user.user-data: |
    #cloud-config
    hostname: foo
    users:
      - default
      - name: user
    ssh_pwauth: false
    disable_root: false
    chpasswd:
      list: |
        ubuntu:linux
        user:password
      expire: false
description: Default LXD profile
devices:
  eth0:
    name: eth0
    network: lxdbr0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: cloud-init
used_by: []

Then:

lxc launch images:ubuntu/focal/cloud uvm1 --vm --profile=cloud-init
lxc console uvm1 --type=vga

IIRC I had trouble setting crypted pass as well. This is not secure way, but I just wanted to tryout cloud-init. Althou this is not what you asked for, it might suit you depending on your needs, or until someone else answer your exact question…

I tried this using this profile:

config:
  security.secureboot: "false"
  user.user-data: |
    #cloud-config
    hostname: foo
    users:
      - default
      - name: user
    ssh_pwauth: false
    disable_root: false
    chpasswd:
      list: |
        ubuntu:linux
        user:password
      expire: false
description: ""
devices:
  eth0:
    nictype: macvlan
    parent: bond0.3
    type: nic
  root:
    path: /
    pool: lxd_storage
    type: disk
name: cloud-init
used_by:
- /1.0/instances/uvm1

I still get:

[FAILED] Failed to start LXD - agent - virtio-fs mount.
[FAILED] Failed to start LXD - agent.

Ubuntu 20.04.1 LTS distrobuilder-ec1a828c-bc5a-4c85-88d6-aeaa9b9f2cf0 ttyS0

distrobuilder-ec1a828c-bc5a-4c85-88d6-aeaa9b9f2cf0 login: user
Password:

I figured this created two accounts? u: user p: password and u: ubuntu p: linux, but that does not seem to work :frowning:

Not sure what image are you using and do you have any special requirements?! If not, try with one from my previous post. And yes, apart from default account ubuntu, this one creates other account user.

hmm.

There seems to be some issue with it finding /boot:

BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
error: file `/boot/' not found.
error: no such device: /.disk/info.
error: no such device: /.disk/mini-info.
[    0.594735] Initramfs unpacking failed: Decoding failed
[FAILED] Failed to start LXD - agent - virtio-fs mount.
[FAILED] Failed to start LXD - agent.

Ubuntu 20.04.1 LTS distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b ttyS0

distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b login:

I scrolled up. I used the above profile and launched with: sudo lxc launch images:ubuntu/focal/cloud uvm1 --vm --profile=cloud-init.

This makes me think it wasn’t booting the VM and was getting stuck in initramfs for some reason.

I think the problem with the crypted password might be something to do with escape sequences. I noticed with the password:

passwd: "$6$jkaSxludpbR9Iy8U$dxlQUZeVTuavn5RIoGhDLwiHcLRYrd2gso3XjYEKRpSUkObRwabwb7f7BBl1JhZ3bwBEy2er3Euw4pGyWq4mD/"

When I looked in lxc config show i found:

users:
      - name: user
        passwd: "/"
        lock_passwd: false
        groups: lxd
        shell: /bin/bash
        sudo: ALL=(ALL) NOPASSWD:ALL

@nula, your method of chpasswd, doesn’t seem to be working for me at all.

I used this profile:

config:
  security.secureboot: "false"
  user.user-data: |
    #cloud-config
    hostname: foo
    users:
      - default
      - name: user
    ssh_pwauth: false
    disable_root: false
    chpasswd:
      list: |
        ubuntu:linux
        user:password
      expire: false
description: LXD VM profile
devices:
  eth0:
    nictype: macvlan
    parent: bond0.3
    type: nic
  root:
    path: /
    pool: lxd_storage
    type: disk
name: cloud-init
used_by: []

With this command:

lxc launch ubuntu:20.04 uvm1 --vm --profile=cloud-init

Okay so i tried this with the same configuration as my ubuntu example in the the first post.

config:
  security.secureboot: "false"
  user.user-data: |
    #cloud-config
    ssh_pwdauth: yes
    users:
      - name: user
        passwd: "\$6\$s.wXDkoGmU5md\$d.vxMQSvtcs1I7wUG4SLgUhmarY7BR.5lusJq1D9U9EnHK2LJx18x90ipsg0g3Jcomfp0EoGAZYfgvT22qGFl/"
        lock_passwd: false
        groups: lxd
        shell: /bin/bash
        sudo: ALL=(ALL) NOPASSWD:ALL
description: LXD VM profile
devices:
  eth0:
    nictype: macvlan
    parent: bond0.3
    type: nic
  root:
    path: /
    pool: lxd_storage
    type: disk
name: cloud-init
used_by: []

You would think the username would be “user” and the password would be “ubuntu”, but no.

sudo lxc launch ubuntu:20.04 uvm1 --vm --profile=cloud-init

Using launch images:ubuntu/focal/cloud (cloud image) I get the familiar initramfs errors from the above post.

This is highly annoying and I’ve spent a lot of time trying to get this working :frowning:.

I just tried it and it works for me, with few “issues”:

  1. I was not able to connect via console
  2. lxc exec uvm2 – sudo --user user --login works, BUT, I had to wait ~30sec

I haven’t had no issue connecting either via console or lxc exec with images:ubuntu/focal/cloud and there was no waiting time to login…

Right, so using:

$ sudo lxc launch ubuntu:20.04 uvm1 --vm --profile=cloud-init
Creating uvm1
Starting uvm1

With this profile:

$ sudo lxc profile show cloud-init
config:
  security.secureboot: "false"
  user.user-data: |
    #cloud-config
    hostname: foo
    users:
      - default
      - name: user
    ssh_pwauth: false
    disable_root: false
    chpasswd:
      list: |
        ubuntu:linux
        user:password
      expire: false
description: LXD VM profile
devices:
  eth0:
    nictype: macvlan
    parent: bond0.3
    type: nic
  root:
    path: /
    pool: lxd_storage
    type: disk
name: cloud-init
used_by:
- /1.0/instances/uvm1

I see it starts, but neither user:password or ubuntu:linux works as username/password.

I see that LXD agent does start and stop a few times:

[  OK  ] Reached target Basic System.
         Starting Accounts Service...
         Starting LSB: automatic crash report generation...
         Starting Deferred execution scheduler...
[  OK  ] Started Regular background program processing daemon.
[  OK  ] Started D-Bus System Message Bus.
[  OK  ] Started Save initial kernel messages after boot.
         Starting Remove Stale Onli…t4 Metadata Check Snapshots...
         Starting LSB: Record successful boot for GRUB...
         Starting GRUB failed boot detection...
[  OK  ] Started irqbalance daemon.
         Starting Dispatcher daemon for systemd-networkd...
         Starting Pollinate to seed…udo random number generator...
         Starting System Logging Service...
         Starting Snap Daemon...
         Starting Login Service...
         Starting Permit User Sessions...
[  OK  ] Started Deferred execution scheduler.
[  OK  ] Finished Permit User Sessions.
[  OK  ] Started System Logging Service.
[  OK  ] Finished GRUB failed boot detection.
         Starting Hold until boot process finishes up...
         Starting Terminate Plymouth Boot Screen...
[  OK  ] Started LSB: automatic crash report generation.
[  OK  ] Started LSB: Record successful boot for GRUB.
[  OK  ] Finished Hold until boot process finishes up.
[  OK  ] Finished Terminate Plymouth Boot Screen.
         Starting Authorization Manager...
[  OK  ] Started Serial Getty on ttyS0.
[  OK  ] Created slice system-getty.slice.
[  OK  ] Reached target Login Prompts.
[  OK  ] Started Authorization Manager.
[  OK  ] Started Accounts Service.
[  OK  ] Finished Pollinate to seed…seudo random number generator.
         Starting OpenBSD Secure Shell server...
[  OK  ] Started Dispatcher daemon for systemd-networkd.
[  OK  ] Started Login Service.
[  OK  ] Started Unattended Upgrades Shutdown.
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Stopped OpenBSD Secure Shell server.
         Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Finished Remove Stale Onli…ext4 Metadata Check Snapshots.
[  OK  ] Started Snap Daemon.
         Starting Wait until snapd is fully seeded...
[  OK  ] Stopped OpenBSD Secure Shell server.
         Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Stopped OpenBSD Secure Shell server.
         Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Stopped OpenBSD Secure Shell server.
         Starting OpenBSD Secure Shell server...
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Stopped OpenBSD Secure Shell server.
[FAILED] Failed to start OpenBSD Secure Shell server.
See 'systemctl status ssh.service' for details.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
         Mounting Mount unit for snapd, revision 9721...
[  OK  ] Mounted Mount unit for snapd, revision 9721.

Ubuntu 20.04.1 LTS ubuntu ttyS0

ubuntu login:          Mounting Mount unit for core18, revision 1932...
[  OK  ] Mounted Mount unit for core18, revision 1932.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
         Mounting Mount unit for lxd, revision 16922...
[  OK  ] Mounted Mount unit for lxd, revision 16922.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Listening on Socket unix for snap application lxd.daemon.
         Starting Service for snap application lxd.activate...
[  OK  ] Finished Service for snap application lxd.activate.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Stopped LXD - agent.
[  OK  ] Started LXD - agent.
[  OK  ] Finished Wait until snapd is fully seeded.
[  OK  ] Reached target Multi-User System.
[  OK  ] Reached target Graphical Interface.
         Starting Update UTMP about System Runlevel Changes...
[  OK  ] Finished Update UTMP about System Runlevel Changes.

ubuntu login: user
Password:

Login incorrect

(this is from sudo lxc console uvm1).

If I use the cloud image:

$ sudo lxc launch images:ubuntu/focal/cloud uvm2 --vm --profile=cloud-ini

All I see is:

BdsDxe: loading Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
BdsDxe: starting Boot0001 "UEFI QEMU QEMU HARDDISK " from PciRoot(0x0)/Pci(0x1,0x1)/Pci(0x0,0x0)/Scsi(0x0,0x1)
error: file `/boot/' not found.
error: no such device: /.disk/info.
error: no such device: /.disk/mini-info.
[    0.595380] Initramfs unpacking failed: Decoding failed
[FAILED] Failed to start LXD - agent - virtio-fs mount.
[FAILED] Failed to start LXD - agent.

Ubuntu 20.04.1 LTS distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b ttyS0

distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b login: user
Password:

Login incorrect
distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b login: ubuntu
Password:

Login incorrect
distrobuilder-55f45f2f-bd15-48d0-bded-9c3e3a5aeb8b login:

That to me looks like initramfs. I just tested again, and I’m on Alpine Linux 3.12 host with LXD 4.7 - though I don’t think that’s the problem.

I wonder where I can go from here to find out more why it’s not working for me. Hopefully someone with more experience might have an idea :thinking:

I do appreciate the help :slight_smile: as I’ve been wracking my brains to find a solution to this annoying, but simple sounding issue.

Passwords containing $ must be escaped, so must any \ or \ that appears in the hash. There must be some other reason why the archlinux guest doesn’t run the cloud-init, and why the profile isn’t being applied.

It would appear the archlinux iso doesn’t have cloud-init installed, therefore no password is set in those.

You have to have mkisofs or genisoimage installed on the host and use the images with vm support.
that was the one solution for me on an alpine host
lxc image list images:distro/release
https://us.images.linuxcontainers.org/