Change a qcow image VM root password

# virt-customize -a /var/lib/libvirt/images/vmtest01.qcow2 --root-password password:redhat --ssh-inject 'root:file:/home/user/.ssh/' 


  • Create the new password and copy it
  • Enter the image,
  • Start it
  • Mount the filesystem
  • Edit the shadow file
  • Paste the password on the second field of the shadow file (fields are separated by “:”)
  • Be happy :)
# openssl passwd -1 <password>
$1$lkeEz0u8$SGtJoqKAtY5l2mDgF/FYt/  (copy this or keep it handy)
# guestfish --rw -a <image-name>
><fs> run
100% ⟦▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒⟧ 00:00
><fs> list-filesystems
/dev/sda1: ext4
><fs> mount /dev/sda1 / (this might be sda or hda)
><fs> vi /etc/shadow