Skip to content

Instantly share code, notes, and snippets.

@teebow1e
Last active December 30, 2025 18:01
Show Gist options
  • Select an option

  • Save teebow1e/5dce04ec0cf76ddfa14f145f1bc4c01c to your computer and use it in GitHub Desktop.

Select an option

Save teebow1e/5dce04ec0cf76ddfa14f145f1bc4c01c to your computer and use it in GitHub Desktop.
reset cloned VMs
#!/bin/bash
# Usage: curl -sSL https://a.xn--c-kia488t.vn/clone | sudo bash -s -- pc1
if [ "$EUID" -ne 0 ]; then
echo "Please run as root (e.g., sudo bash script.sh)"
exit 1
fi
NEW_HOSTNAME=$1
if [ -z "$NEW_HOSTNAME" ]; then
echo "Usage: curl -sSL [URL] | sudo bash -s -- [new-hostname]"
exit 1
fi
# 1. Update the hostname
hostnamectl set-hostname "$NEW_HOSTNAME"
# 2. Update /etc/hosts to prevent sudo resolution delays
sed -i "s/^127.0.1.1.*/127.0.1.1\t$NEW_HOSTNAME/" /etc/hosts
# 3. Regenerate SSH Host Keys
rm -f /etc/ssh/ssh_host_*
dpkg-reconfigure openssh-server
# 4. Reset Machine ID for unique system identification (useful for cloned VMs)
rm -f /etc/machine-id
dbus-uuidgen --ensure=/etc/machine-id
rm -rf /var/lib/dhcp/* 2>/dev/null
rm -rf /var/lib/NetworkManager/*.lease 2>/dev/null
systemctl reboot
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment