Unable to Login to DU-VM After Changing DU-Host SSH-Key

Problem

Unable to access on-prem management plane once the SSH-public key has been changed on the DU host VM.

[centos@onprem-du-host-5-3 .ssh]$ ssh centos@192.168.120.254
Permission denied (publickey)

Environment

  • Platform9 Edge Cloud - All Versions

Cause

  • SSH public key reset from the Host. [Generating new SSH key pair in the Host] and the DU VM being unaware about the new public key of the SSH.

Resolution

You need to copy the new SSH key [id_rsa.pub] into the DU VM /home/centos/.ssh/authorized_keys file to fix this issue. To resolve this issue, follow the below steps :

  1. To access DU VM via Single-User mode, login to the DU host server via SSH, List the DU VM with virsh commands to ensure the VM is in running status:

$ sudo virsh list --all
Id Name State

----------------------------------------------------

1 pf9-mplane running
$ sudo virsh net-dhcp-leases pf9-mplane

Expiry Time MAC-address Protocol IP-address Hostname Client-ID or DUID

------------------------------------------------------------------------------

2022-01-31 10:41:08 50:e4:cb:c0:0a:02 ipv4 192.168.120.254/24 pf9-mplane --
  1. Now reboot the DU VM and access the VM console using the virsh command:

$ sudo virsh reboot pf9-mplane; sudo virsh console pf9-mplane
  1. In the console find the kernel line starting with linux16. And add rd.break at the end of this line. And press CTRL+X to resume the OS booting process with the new settings.

linux16 /boot/vmlinuz-3.10.0-1160.49.1.el7.x86_64 root=UUID=f856d385-fe64-4188-b4f8-51f6089b75e6 ro console=tty0 console=ttyS0,115200n8 crashkernel=\ auto console=ttyS0,115200 LANG=en_US.UTF-8 rd.break
  1. Once you get the shell access, mount the /sysroot in rw read-write mode using the below command:

switch_root:/# mount -oremount,rw /sysroot
  1. To treat the directory as a root and to redirect to the shell prompt use

switch_root:/# chroot /sysroot

6. Now append the new SSH public key [id_rsa.pub] of the DU host into the below file in the DU VM and save it. And restart the sshd service:

sh-4.2# vi /home/centos/.ssh/authorized_keys
sh-4.2# systemctl restart sshd
  1. After making any changes, it is recommended to relabel the file system to make all the applications start with the proper label.

sh-4.2# touch /.autorelabel
  1. Now exit from the shell which will automatically boot the DU VM with newly added SSH key:

sh-4.2# exit

exit

switch_root:/# exit
  1. Now, from the DU host, try to SSH into the DU VM using the below command. You should be able to login to the VM using the new SSH pub key added.

$ ssh centos@192.168.120.254

Last login: Mon Jan 31 09:19:32 2022 from 192.168.120.1

[centos@airctl-1 ~]$