cloud-init - set root password with a config iso

This is useful for running cloud-init VMs locally, particularly if the image doesn’t have sudo or some other privilege escalation tool. Usually in an actual cloud environment you wouldn’t do this.

you will need the following commands:

cloud-localds comes from a package usually called cloud-utils on distributions that have it. Gentoo does not, so I used nix-shell -p cloud-utils to use the nixpkgs build of it.

generate a password hash:

mkpasswd -m sha512crypt

This will prompt for a password and provide a hash. Here’s the hash for ergosphere. Your hash should look like this too:

$6$8Q6mhBP3mpXVaESC$STC9rjLChG54I.Xlj3/mRwInf.YSJnToe8GOKDO5jwDUnXqPmLBWzYxWrc6bCOnfIXqJqNMJBjIabHSVumCe80

create a file config.yaml, with your hash in it:

#cloud-config
users:
- name: root
  lock_passwd: false
  # replace with your password's hash
  hashed_passwd: $6$8Q6mhBP3mpXVaESC$STC9rjLChG54I.Xlj3/mRwInf.YSJnToe8GOKDO5jwDUnXqPmLBWzYxWrc6bCOnfIXqJqNMJBjIabHSVumCe80

generate config.iso:

cloud-localds config.iso config.yaml

attach config.iso to your VM as a cdrom before boot.