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
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
Then run the following command, for the Centos7 virtual machine:
guestfish --rw -a /var/lib/libvirt/images/centos7.0.qcow2
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
For example: The same for ubuntu virtual machines
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:
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
- 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)