Skip to content

Instantly share code, notes, and snippets.

@reski-rukmantiyo
Created January 31, 2026 10:43
Show Gist options
  • Select an option

  • Save reski-rukmantiyo/48b4c7a87444909493d343a785351c85 to your computer and use it in GitHub Desktop.

Select an option

Save reski-rukmantiyo/48b4c7a87444909493d343a785351c85 to your computer and use it in GitHub Desktop.
Generate new Linux ID
#!/bin/bash
# Run as root or with sudo
# Machine ID
rm -f /etc/machine-id /var/lib/dbus/machine-id
systemd-machine-id-setup
# SSH keys
rm /etc/ssh/ssh_host_*
ssh-keygen -A
# Hostname (change as needed)
read -p "Enter new hostname: " NEW_HOSTNAME
hostnamectl set-hostname "$NEW_HOSTNAME"
# Clean cloud-init if present
if [ -d /var/lib/cloud ]; then
cloud-init clean
rm -rf /var/lib/cloud/instances/*
fi
echo "System IDs regenerated. Reboot recommended."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment