Resolve SSH Key Mismatch

From time to time, usually when an OS is updated, the ssh key on a server may change and your ssh client will warn you of an ssh key mismatch and not let you connect.  This warning is to let you know something has changed in the identity of the server.  If you expected this change (for example by us emailing you letting you know a server will be updated) then it's okay to go ahead and remove the old key.

This example shows removing a key stored in your home directory on our Linux systems and are for if you connect to lts.cla.umn.edu and ssh from there.  If you are sshing directly from a Mac or PC to a system these instructions may not be right for you.

Use the following commands in the terminal on lts.cla.umn.edu or another LATIS Linux server.  In the below example we'll use the server apollo and its IP address.

First, find the IP address of apollo by typing nslookup apollo.cla.umn.edu

goldy@lts:~ 8% nslookup apollo.cla.umn.edu
Server:        128.101.101.101
Address:    128.101.101.101#53

Non-authoritative answer:
Name:    apollo.cla.umn.edu
Address: 134.84.184.14

This tells us the IP address for apollo is 134.84.184.14.

Next, we'll enter the ssh-keygen command with a -R (remove) 3 different times using the most common names that may be stored.

goldy@lts:~ 9% ssh-keygen -R apollo
/home/goldy/.ssh/known_hosts updated.
Original contents retained as /home/goldy/.ssh/known_hosts.old
goldy@lts:~ 10% ssh-keygen -R apollo.cla.umn.edu
/home/goldy/.ssh/known_hosts updated.
Original contents retained as /home/goldy/.ssh/known_hosts.old
goldy@lts:~ 11% ssh-keygen -R 134.84.184.14
/home/goldy/.ssh/known_hosts updated.
Original contents retained as /home/goldy/.ssh/known_hosts.old
goldy@lts:~ 12%

This should remove any entries for apollo from your known_hosts file. When you try to reconnect it will alert you that it is adding the new host key and then let you connect.  Remember, this example uses the server apollo so if it's another server you need to remove the commands will need to change appropriately.