Managing SSH Host Keys in 20.04 Autoinstall/Cloud Init

I want to manage the generation of SSH host keys during a build of a 20.04 VM. The default is that on first boot cloud-init deletes any host keys and creates fresh ones.

The autoinstall docs don't talk about this. The cloud init docs talk about being able to use the "ssh_deletekeys: false" parameter to control this.

I've tried putting this at the top of my user-data file. i.e.

#cloud-config
ssh_deletekeys: false
autoinstall:
...

That didn't work. I also tried manually adding it to the /target/var/lib/cloud/seed/nocloud-net/user-data prior to first reboot, but that didn't work either.

What am I doing wrong?


I think you should put ssh_deletekeys: false in the configuration file at /etc/cloud/cloud.cfg. At least it worked for me under Debian 10.

Example:

# The top level settings are used as module
# and system configuration.

ssh_deletekeys: false

# A set of users[...]