'SSH Remote Host Identification Has Changed Error and Unable To Modify SSH Keys

I have a MacBook and by mistake I tried to setup password less ssh access for GitHub and definitely messed things up. I am new to Macs and I have no idea how to solve the below.

When I try to establish a ssh connection, I get the following

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
SHA256:DrvZ0osXO8YCnPwEaWyiGKf/SxQGcCZBoNcPrhEdKmI.
Please contact your system administrator.
Add correct host key in /Users/rakeshravi/.ssh/known_hosts to get rid of this message.
Offending RSA key in /Users/rakeshravi/.ssh/known_hosts:4
RSA host key for rivanna.hpc.virginia.edu has changed and you have requested strict checking.
lost connection

From what I found in online forums, I was trying the following command but to no avail.

ssh-keygen -R hostname

I get the following as response.

do_known_hosts: hostkeys_foreach failed: No such file or directory



Solution 1:[1]

You can open with your favorite editor file /Users/rakeshravi/.ssh/known_hostsand delete line 4 and save the file. And next time you try to connect to the host you will be asked to add the new key to known_hosts

Solution 2:[2]

Add the option -o "StrictHostKeyChecking no". This will suppress any checking. Example:

    ssh root@localhost -o "StrictHostKeyChecking no"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Romeo Ninov
Solution 2 Martlark