How to delete ssh host keys and machine-id to create a new NixOS template on Proxmox
- Delete ssh host keys:
# Delete the host keys
sudo rm /etc/ssh/ssh_host_*
- Delete machine-id:
# Get current machine-id
cat /etc/machine-id > /tmp/machine-id.ORIG
# Delete current machine-id
sudo truncate -s 0 /etc/machine-id
- Now, shutdown the VM and convert into a Proxmox VM Template.
How to generate ssh host keys and machine-id on the new NixOS VM generated from the template
Create a new VM from the NixOS template: Right click the template, then choose “Clone”.
Generate ssh host keys:
# Re-generate the host keys
sudo ssh-keygen -A
# Restart ssh daemon to use the new keys
sudo systemctl restart sshd
- Generate machine-id: This will be auto-generated on boot, courtesy of systemd. Case not, below are the instructions to create a new one.
# check machine-id
cat /etc/machine-id
# Get current machine-id (will be different from the one on the template, that is stored at /tmp)
diff /etc/machine-id /tmp/machine-id.ORIG
# Generate new machine-id
sudo systemd-machine-id-setup
# Get current machine-id (will be different from the one on the template, that is stored at /tmp)
diff /etc/machine-id /tmp/machine-id.ORIG