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
- 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
Maybe you are interested
Instructions for inserting square root symbol in Powerpoint
Instructions to root Android easily and quickly - Experience new features
Does Rooting Android Lose Data? Important Information
How to reset SoftwareDistribution and Catroot2 folders on Windows 11 PC
How to Check if Android Phone is Rooted
How to Enter Square Roots on PC or Mac