While working on KVM virtual machines, I once locked out of the guess VMs due to ufw enabled and I forgot to allow port 22. After my session is timed out, I cannot connect to my VMs through SSH anymore. The following is the steps to gain access to the VMs and then enable SSH to access them.
Gain Console Access to VM
Since SSH is blocked by the firewall on the VM, we have to find another way to connect.
Login to the host machine and try “virsh console api”. Chances are it is stuck there without login prompt.
We need to enable console access from the VM. As we cannot login to the VM, we must use virt-edit to update the grub.cfg on the VM to allow ttyS0.