Use below steps to recover the password for the lab devices. 

Helpful when we load customer cdb in which passwords are not default

Source: https://www.cyberciti.biz/faq/how-to-reset-forgotten-root-password-for-linux-kvm-qcow2-image-vm/

 

 

versa@ubuntu:~$ sudo apt install libguestfs-tools

versa@ubuntu:~$ virsh shutdown Branch-01

versa@ubuntu:~$ virsh dumpxml Branch-01 | grep 'source file'

      <source file='/home/versa/images/Branch21.2.3/versa-flexvnf-67ff6c7-21.2.3.qcow2'/>

 

versa@ubuntu:~$sudo guestfish --rw -a /home/versa/images/Branch21.2.3/versa-flexvnf-67ff6c7-21.2.3.qcow2

[sudo] password for versa:

 

><fs> launch

 

 100% ▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒ 00:00

><fs>

><fs> list-filesystems

 

/dev/sda1: ext2

/dev/sda2: unknown

/dev/system/root: ext4

/dev/system/swap_1: swap

 

><fs> mount /dev/system/root /

 

><fs> vi /etc/shadow

 

admin:$6$wZa2qkpxDTL/$T595MNJCK.FZ7cOExJrWhtDBDjxY1pWfDVRR131.8UnaBCry/KEBV6N6UdzXDxzfvzh4kvV3GcWBd0qYI1.gS.:19709:0::7:::     >>>paste this line (removing existing admin line, copied from another working device)

wq


><fs>exit

 

versa@ubuntu:~$ virsh start Branch-01


Login with admin/versa123


Configure the admin password from cli for the sudo password to work.

(config)% set system users admin password versa123

(config)% commit

Commit complete.