WRITELOOP

PREPARE A VM/LXC CONTAINER TEMPLATE ON PROXMOX FOR NIXOS

When generating a template VM or LXC container, you need to swipe and re-generate some configuration so that the VM/LXC container generated becomes unique from the Proxmox's perspective. Here is a description on what is needed.

2023 October 10

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

NOTE: The original content(s) that inspired this one can be found at:

All copyright and intellectual property of each one belongs to its' original author.