When connecting with an SFTP client or SSH via the terminal on a Mac, you may see the error “warning: remote host identification has changed!” This prevents you from connecting to your website or server. And it always seems to show up at the most inconvenient time. Here are a few quick, easy ways to fix the error and reconnect.
What is the “warning: remote host identification has changed!” error?
The error below typically occurs when your SSH keys or the server’s connection information has changed. For example, if you recently migrated your website to a new hosting provider, your IP address may have changed. Or sometimes hosting providers make behind-the-scenes changes.
Your known_hosts file stores the server’s public host key. When you use an SFTP client (one of our favorites is ForkLift), it uses the information to connect to the web server.
[user@hostname ~]$ ssh root@user
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ 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
xx:xx:xx.
Please contact your system administrator.
Add correct host key in /home/hostname /.ssh/known_hosts to get rid of this message.
Offending RSA key in /var/lib/sss/pubconf/known_hosts:3
RSA host key for xxx.xxx.xx.xxx has changed and you have requested strict checking.
Host key verification failed.
How to fix your known_hosts file on Mac
There are a couple of ways to fix your known_hosts file on a Mac. Often, we prefer using an app because it’s quick and easy, and you don’t have to remember terminal commands. But we’ll walk you through both methods.
Note: The error can happen on Windows too, but it’s quite rare.
- Option 1: Fix known_hosts file with an app (easiest method)
- Option 2: Fix known_hosts file from the terminal
Option 1: Fix known_hosts file with an app (easiest method)
An app called SSH Config Editor lets you manage your SSH client configuration file and other settings. There is a Pro version, and we always recommend supporting developers when you can. If you’re on a tight budget, the free version is enough to manage your known_hosts file. Follow the steps below.
Step 1
Install the free SSH Config Editor app.
Step 2
Open SSH Config Editor and click on “File → Open Known Hosts.”
Step 3
Find and highlight the entry with the issue. If you’re not sure which one to choose, look up your old and current IP address. If you’re hosting with a provider like Kinsta, this is called your “Site IP address” and you can find it in your MyKinsta dashboard.
Then click the trash can icon to delete the entry. Another option is to remove all entries.
Step 4
Click “Remove” on the following prompt:
Do you want to remove “[xx.xxx.xx.xxx]:xxxxxx” from known hosts?
Step 5
Close the window and click “Save” on the following prompt:
Do you want to save the changes made to the document “known hosts”?
You should now be able to connect to your website and or server again.
You probably won’t need the SSH Config Editor app that often. We recommend leaving it installed for the occasions when you do get the connection error.
Option 2: Fix known_hosts file from the terminal
The second option is to clean up the entry from your known_hosts file using the terminal. Follow the steps below.
Step 1
Open the Terminal app. The quickest way is to launch Spotlight and search for “terminal.” Or you can find it under “Utilities → Terminal.”
Step 2
Paste the following command.
nano ~/.ssh/known_hosts
Step 3
Remove the entry that is causing the issue. If you aren’t sure which one to choose, look up your old and current IP address. Another option is to remove all entries.
Step 4
Type Ctrl + X (^X) to exit and select Y for yes when prompted if you want to save the modified buffer.
You should now be able to connect to your website and/or server again.
Alternatively, you could delete your entire known_hosts file and let it repopulate. Enter the following command in the terminal.
rm .ssh/known_hosts