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

  1. Shut the VM down: virsh shutdown vm2 (virt-sysprep must never run on a running VM).
  2. Run it on the libvirt domain: virt-sysprep -d vm2, or on an image file: virt-sysprep -a /var/lib/libvirt/images/vm2.qcow2.
  3. 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.

Related services

KVM VPS hosting

NVMe SSD and full root access, with Free Basic Managed Support.

Unmanaged dedicated servers

full root access and free IPMI KVM, with Free Basic Managed Support.

Managed dedicated servers

our engineers look after the server for you, from $135 a month.

Was this answer helpful?

Still stuck? Open a ticket