Open menu

Debian Template 12 Template on Proxmox

28 May 2025

Do you want to make a Debian 12 template?

Your in the right place, I have 2 files that will reset debian and allow you to template it.

  • template.sh
  • regenerate_ssh_host_keys.service
#!/bin/sh

apt update && apt dist-upgrade; \
truncate -s0 /etc/machine-id; \
truncate -s0 /etc/resolv.conf; \
rm -f /var/lib/dbus/machine-id; \
rm -f /etc/ssh/ssh_host_*; \
systemctl enable regenerate_ssh_host_keys.service; \
cat /dev/null > ~/.bash_history && history -c; \
shutdown -h now
[Unit]
Description=Regenerate SSH host keys
Before=ssh.service
ConditionFileIsExecutable=/usr/bin/ssh-keygen

[Service]
Type=oneshot
ExecStartPre=-/bin/dd if=/dev/hwrng of=/dev/urandom count=1 bs=4096
ExecStartPre=-/bin/sh -c "/bin/rm -f -v /etc/ssh/ssh_host_*_key*"
ExecStart=/usr/bin/ssh-keygen -A -v
ExecStartPost=/bin/systemctl disable regenerate_ssh_host_keys

[Install]
WantedBy=multi-user.target

The first file is the main script, it will:

  • update the OS with apt
  • empty the machine-id files
  • empty the resolver config file
  • enable a systemd service to regenerate SSH host keys
  • clear roots history
  • shutdown the server

The systemd service will regenerate SSH host keys and disable the service


Back: Nextcloud whiteboard (Nextcloud whiteboard)
Forward: Grub failed (Recover From Grub Failure)