Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM
Suppose you set a root password for the virtual machine on KVM, but forgot it. So, how to gain root access? Please use Guestfish to reset the root password in qcow2 format on KVM. Here is what you need to prepare and do.
Prepare LAB lesson
- On a VMware environment, use a CentOS 7 virtual machine with KVM installed.
- Create a CentOS 7.0 virtual machine with qcow2 format
Proceed to set the root password
Step 1: Install Guestfish
yum install libguestfs-tools -y
Step 2: Shutdown the virtual machine
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 1
virsh shutdown tên_máy_ảo
Step 3: Reset, change the root password using Guestfish
Note: First create a new root user password by typing the following command and then using the encrypted password to change.
openssl passwd -1 pass_mới
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 2
Then run the following command, for the Centos7 virtual machine:
guestfish --rw -a /var/lib/libvirt/images/centos7.0.qcow2
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 3
Next use the following commands
> launch > list-filesystems #liệt kê các phân vùng /dev/sda1: xfs /dev/centos/root: xfs /dev/centos/swap: swap > mount /dev/centos/root / #lưu ý lựa chọn mount vào phân vùng của hệ thống có chứa thư mục /etc. > vi /etc/shadow #chỉnh sửa file shadow
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 4
For example: The same for ubuntu virtual machines
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 5
After running the vi / etc / shadow command, fix the encrypted pass at root with the new encrypted pass from the openssl command above and save it:
Use Guestfish to reset the forgotten root password for the virtual machine in qcow2 format on KVM Picture 6
Then exit Guestfish:
> quit
Step 4: Open the virtual machine with virt-manager and enter the new password
So you have finished resetting the forgotten root password for the virtual machine in qcow2 format on KVM.
You should read it
- Forgot your iCloud password and the fastest way to recover
- How to retrieve a Tik Tok password when it is lost
- How to fix the error of creating Password Reset Disk on Windows
- How to reset the password for sudo in Debian
- How to reset Admin password on Windows with Sticky Keys
- 3 ways to simply retrieve the Momo password
- Create Windows Password Reset Disk on Windows 7 with USB Flash Drive
- How to Use a Password Reset Disk (Windows)
- How to change Snapchat password on phone and computer
- How to Reset Admin Password on Mac OS X
- How to use Password Reset Disk to reset Windows password?
- Fix some errors when using Password Reset Wizard