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

  1. On a VMware environment, use a CentOS 7 virtual machine with KVM installed.
  2. 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.

4.2 ★ | 13 Vote

May be interested

  • How to Reset Windows 7 PasswordHow to Reset Windows 7 Password
    if you forget your windows 7 password, you will have to reset your user account password to log in. windows 7 passwords can be reset by your network administrator if your computer is in a domain, or can be reset using a password reset disk if your computer is in a homegroup or workgroup. this article will teach you to reset windows 7 password in both ways.
  • How to Use a Password Reset Disk (Windows)How to Use a Password Reset Disk (Windows)
    if you forget your password, you can log on to the computer by using a new password you created using the password reset wizard and your password reset disk. in the welcome to windows dialog box, press ctrl+alt+delete and log off.
  • How to Change Root Password in LinuxHow to Change Root Password in Linux
    this tipsmake article shows how to change the root password in the linux operating system, applicable in cases where you remember your current password or cannot remember your root password.
  • How to fix the error of creating Password Reset Disk on WindowsHow to fix the error of creating Password Reset Disk on Windows
    if you forget your computer login password, you can use password reset disk to create a new password. but what if this option fails?
  • How to use Password Reset Disk to reset Windows password?How to use Password Reset Disk to reset Windows password?
    in previous articles, network administrator showed you how to create a password reset disk on windows 7/8/10. in the following article, network administrator will guide you how to use password reset disk to reset windows password.
  • Fix some errors when using Password Reset WizardFix some errors when using Password Reset Wizard
    when you forget your windows computer login password, you can use the password reset wizard to create a new login password. however, in some fields when using password reset wizard, some users encounter an error: an error occurred while the wizard was attempted to set the password for the user account.
  • How to Change the Root Password in LinuxHow to Change the Root Password in Linux
    this wikihow teaches you how to change the linux root password if you have the current password or if you don't have access to the current root password. open a terminal window. to do so, press ,https://help.ubuntu.com/community/usingthe...
  • How to Change Your Apple ID PasswordHow to Change Your Apple ID Password
    this wikihow teaches you how to change your apple id password on a computer or on your iphone. if you've forgotten your apple id password, you'll need to reset your apple id password instead. open the apple id website. go to...
  • How to Reset a Lost Admin Password on Mac OS XHow to Reset a Lost Admin Password on Mac OS X
    if you're logged into your mac with your apple id account, you may be able to use it to reset your admin password. if you aren't you can use recovery mode on your mac to open the reset password utility. you can also reset a password with...
  • How to retrieve a Tik Tok password when it is lostHow to retrieve a Tik Tok password when it is lost
    tik tok password can be retrieved via email or via phone number registered tik tok account, when users forget or lose the password tik tok.