Updated: 28 September 2026 · Applies to: Ubuntu 24.04, Debian 12, AlmaLinux 9 and Rocky Linux 9
virt-sysprep resets a cloned KVM virtual machine: it removes SSH host keys, machine ID, log files, bash history, network MAC settings and similar data, so each clone is unique. It is part of libguestfs.
Install
dnf install guestfs-tools # AlmaLinux / Rocky 9 apt install libguestfs-tools # Ubuntu / Debian
Reset a clone
- Shut the VM down:
virsh shutdown vm2(virt-sysprep must never run on a running VM). - Run it on the libvirt domain:
virt-sysprep -d vm2, or on an image file:virt-sysprep -a /var/lib/libvirt/images/vm2.qcow2. - Start the VM. It creates new SSH host keys and a new machine ID at boot.
Useful options
virt-sysprep --list-operations # everything it can reset virt-sysprep -d vm2 --operations defaults,-ssh-userdir # defaults, but keep users' ~/.ssh virt-sysprep -d vm2 --hostname vm2.example.com --root-password password:NewPass123 virt-sysprep -d vm2 --selinux-relabel # for AlmaLinux / Rocky guests
Tip: Clone a VM first with virt-clone --original vm1 --name vm2 --auto-clone, then run virt-sysprep on the clone.