"WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!" means the server answered with a different host key from the one your client recorded, and the usual advice to delete the line from known_hosts throws away the only check that tells a rebuilt server apart from an interception. Most of the time the cause is innocent: a reinstalled machine, a recycled cloud IP address, a load balancer or a provider rotating its key. Occasionally it is a man-in-the-middle, and the warning exists precisely for that case. This guide gives an ordered way to work out which it is, how to verify the new key out of band, how to replace only the affected entry, and how to stop fleets and pipelines producing the warning at all. It is for engineers, platform teams and anyone who maintains SSH-based automation. Authentication failures after the host key is accepted are covered in the SSH Permission Denied (publickey) Troubleshooting Guide.
Key takeaways
- The warning is the security control working. OpenSSH refuses the changed key under its default
asksetting and disables password authentication for that connection to prevent server spoofing or man-in-the-middle attacks. - Find a reason before you remove anything. A planned rebuild, a reused IP address or a published provider rotation explains most warnings; no explanation means stop and investigate.
- Verify the fingerprint through a second channel. Compare against the server console, a cloud provider's boot log, a published fingerprint list or DNSSEC-signed SSHFP records, never against what the suspect connection shows you.
- Remove one entry, not the file.
ssh-keygen -R hostremoves the keys for that host (including hashed entries); deleting known_hosts discards every other server's verified key. - Fix the cause at fleet scale. SSH host certificates with
@cert-authority, managed global known_hosts files andaccept-newonly where first-use trust is acceptable remove the habit of clicking past warnings.
What the warning actually means
When you first connect, the client stores the server's public host key in ~/.ssh/known_hosts (or checks /etc/ssh/ssh_known_hosts, the global file). On every later connection the server proves it holds the matching private key, one of the files such as /etc/ssh/ssh_host_ed25519_key. If the presented key does not match what is recorded for that name, OpenSSH prints the warning, names the known_hosts file and line that holds the old key, shows the new fingerprint (SHA256 by default) and stops. The StrictHostKeyChecking option decides what happens next.
| StrictHostKeyChecking value | New, unknown host | Changed key for a known host | Where it fits |
|---|---|---|---|
ask (default) | Added only after you confirm | Refused | Interactive use |
yes | Never added automatically | Refused | Automation with pre-distributed keys or host certificates |
accept-new | Added automatically | Refused | Pipelines where first-use trust is accepted but changes must stop the job |
no or off | Added automatically | Allowed, subject to some restrictions | Avoid; it removes the protection this warning provides |
The point of the table: accept-new is often the right answer for automation, and no almost never is. Setting StrictHostKeyChecking=no with UserKnownHostsFile=/dev/null to silence the warning, a pattern copied widely between scripts, turns every connection into trust on every use.
Triage: innocent change or interception?
Work through these questions in order before touching known_hosts. Write down the answers; they are your evidence if the change turns out to be hostile.
- Was the host rebuilt, reinstalled or restored? A fresh operating system install or a new image generates new host keys unless the old ones were carried over. Check the change record or ask the owner.
- Is the name or IP now a different machine? Cloud IP addresses and DHCP leases are reused. An entry for
10.0.4.17may refer to an instance destroyed last month. - Are several servers behind one name? A load balancer or DNS round robin in front of hosts with different keys produces intermittent warnings. That is a design fault to fix, not a reason to stop checking.
- Did the provider announce a rotation? Git hosting services and appliance vendors publish key changes. GitHub replaced its RSA host key on 24 March 2023 after the private key was briefly exposed in a public repository, and users connecting with RSA saw exactly this warning. See the GitHub RSA SSH Host Key Exposure 2023.
- Did only the key type change? If you previously recorded an RSA key and the server now offers Ed25519 (or the reverse) after a client or server upgrade, compare against the fingerprint for the same type.
- Are you on an untrusted network? Hotel, conference or public Wi-Fi, a new VPN, or a network where other hosts also show changed keys raises the likelihood of interception. Disconnect and try from a known network.
If none of the first five explains the change, treat it as a possible MITRE ATT&CK T1557 Adversary-in-the-Middle event: do not connect, and report it with the old and new fingerprints, the time, your network and the host name.
| Cause | Typical signs | Safe response |
|---|---|---|
| Server rebuilt or reimaged | Change ticket exists; owner confirms | Verify new fingerprint from the console, replace entry |
| IP or name reused | Entry is by IP; host was recently recreated | Verify, replace entry; prefer names or HostKeyAlias over raw IPs |
| Load balancer or round robin | Warning comes and goes for one name | Give each backend the same host certificate or a stable alias per host |
| Provider key rotation | Public announcement; many users affected at once | Check the provider's published fingerprints over HTTPS, replace entry |
| Key type change after upgrade | Warning names a different algorithm | Verify the fingerprint for that type, then replace |
| Interception | No change explains it; untrusted network; other hosts affected | Do not connect; preserve evidence; escalate to security |
Verify the new key out of band
Verification means obtaining the expected fingerprint through a path the possible attacker does not control, then comparing it with the fingerprint in the warning. The OpenSSH manual shows the server-side command: ssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub, run on the host itself (through a console, not over the suspect SSH path).
| Source of truth | How to get the fingerprint | Notes |
|---|---|---|
| Server console | Hypervisor, out-of-band management or physical console; run ssh-keygen -l -f on each .pub host key file | Strongest check for servers you own |
| Cloud boot log | Amazon EC2: "Get system log" or aws ec2 get-console-output, then read between BEGIN SSH HOST KEY FINGERPRINTS and END SSH HOST KEY FINGERPRINTS | Available after first boot; AWS notes output varies by operating system and AMI |
| Published provider list | Provider documentation page or API over HTTPS (GitHub publishes SHA256 fingerprints and a /meta API with ssh_keys and ssh_key_fingerprints) | Relies on TLS and the provider's web PKI, a different channel from SSH |
| SSHFP records | VerifyHostKeyDNS=yes with records generated by ssh-keygen -r | RFC 4255 says a key verified this way must not be trusted unless the record is DNSSEC-authenticated |
| Configuration management | Fingerprints recorded when the host was built, in an inventory or CMDB you trust | Only as good as the record's integrity |
Compare the full fingerprint, matched to the key type the client displays. A cloud log typically lists ECDSA, Ed25519 and RSA fingerprints, and the client shows only one. VisualHostKey=yes prints an ASCII art pattern that makes casual comparison easier, but the OpenSSH manual notes that similar patterns are only a good probability, not proof. Do not use ssh-keyscan output from the same network as verification: its manual says it cannot verify the authenticity of the keys it obtains, and building a known_hosts file from unverified scans leaves users exposed to man-in-the-middle attacks.
Replace only the affected entry
- Record the evidence: copy the warning text, including the old file and line number and the new fingerprint.
- Look before you remove:
ssh-keygen -F hostnamelists matching entries, including hashed ones, and works with[hostname]:portfor non-standard ports. - Back up the file: copy
~/.ssh/known_hostsbefore editing. - Remove the old keys for that host:
ssh-keygen -R hostname(and again for the IP address ifCheckHostIPstored one, or-R '[hostname]:2222'for a port). The manual notes this is the way to remove hashed entries, which you cannot find by eye. - Add the verified key: connect, compare the prompted fingerprint against your out-of-band value, and answer yes only on a match. For provider keys, add the published known_hosts lines from the provider's HTTPS page instead.
- Check the other files: if the old key is also in
/etc/ssh/ssh_known_hosts, a CI image or a configuration management template, fix it there or the warning returns.
Rollback is simple: restore the backup copy of known_hosts. Never "fix" the warning by deleting the whole file, by running ssh-keyscan into known_hosts on an untrusted path, or by adding -o StrictHostKeyChecking=no to a command and moving on.
Automation, CI and Git remotes
Pipelines hit this warning when a runner image carries stale keys or a target is rebuilt. The temptation is to disable checking in the job; the safer patterns are:
- Pin keys as configuration: store the verified known_hosts lines for each target as a pipeline variable or file, and set
StrictHostKeyChecking=yes. A rotation then fails loudly and someone updates one value after verifying it. - Use
accept-newfor ephemeral targets: where the job creates the host itself and has no earlier record, first-use trust is acceptable; changed keys still stop the job. - Update pinned Git host keys on rotation: GitHub's 2023 notice warned that workflows using
actions/checkoutwith thessh-keyoption could fail and that workflows pinned to a commit SHA needed updating. - Avoid
UserKnownHostsFile=/dev/null: it discards every check; if a job needs isolation, give it its own known_hosts file with pinned entries. - Use
KnownHostsCommandfor dynamic fleets: it lets ssh fetch keys from an inventory service in known_hosts format, so the source of truth is central rather than per runner.
The service accounts and deploy keys these pipelines use are machine identities in their own right; see the SSH Key Management Guide.
Prevent the warning at fleet scale
| Approach | How it works | Best for | Trade-off |
|---|---|---|---|
| Host certificates | Clients trust a CA through an @cert-authority line; rebuilt hosts get a new signed certificate | Medium and large fleets, autoscaling | CA key must be protected and signing automated |
| Managed global known_hosts | /etc/ssh/ssh_known_hosts distributed by configuration management | Stable server estates | Every rebuild needs a file update |
| Preserve host keys on rebuild | Restore the original host key files from a secrets store to the new instance | Long-lived names with planned rebuilds | Host private keys become secrets to manage and rotate |
| UpdateHostKeys | Client learns extra keys a trusted server offers, easing planned rotation | Rotating to a new algorithm | Only for hosts already verified in the user known_hosts file, OpenSSH 6.8 or later servers |
| SSHFP with DNSSEC | Fingerprints published in signed DNS, checked with VerifyHostKeyDNS | Organisations already running DNSSEC validation | Without validated DNSSEC it adds no trust |
The @revoked marker lets you list a host key that must never be accepted, which is useful after a host key is exposed. Host certificates are covered in depth in the SSH Protocol and Certificate Authority Guide, and server-side settings in the OpenSSH Server Hardening Guide.
Small and large estates: a team with a dozen servers can keep a managed global known_hosts file and verify by console on every rebuild. Once instances are created by automation or rebuilt weekly, manual verification stops happening in practice, and host certificates are the only approach that keeps verification real without asking people to compare strings.
Where identity fits
A server host key is a machine identity: it is how a client knows which server it reached. Treat host private keys like any other credential, inventoried, protected and rotated on exposure, because a copied host key lets an attacker impersonate the server without triggering this warning at all. That is why GitHub rotated its key in 2023 even with no sign of abuse. If a host key may have been copied, follow the SSH Key Compromise Response Playbook.
Detection and measurement
- Unexplained warnings: changed host key reports with no matching change ticket or provider notice; target zero, investigate each one.
- Disabled checking in code: count of scripts, pipelines and configs containing
StrictHostKeyChecking=noorUserKnownHostsFile=/dev/null; drive towards zero. - Certificate coverage: share of hosts presenting a CA-signed host certificate.
- Rebuild-to-update time: time from a host rebuild to the managed known_hosts or certificate being updated.
- Host key age and exposure: hosts whose keys have not rotated after a known exposure, or that still offer only legacy key types.
Common failure patterns
- Deleting known_hosts wholesale. One stale entry is fixed and every other server's verified key is lost, so the next interception looks like a first connection.
- Disabling host key checking in automation. A copied snippet with
StrictHostKeyChecking=nolives on in pipelines for years. - Verifying against the suspect connection. Running
ssh-keyscanfrom the same network and calling it verification proves nothing. - Load balancers in front of SSH with different keys. Users learn that the warning is normal and stop reading it.
- Leaving the old key in a global file or image. The user entry is fixed but the CI image or global file still holds the old key, and the warning returns.
- Ignoring a provider's rotation notice. Pinned keys in workflows break, and the quick fix is to disable checking rather than update the pin.
Framework mapping
| Framework | Reference | Relevance |
|---|---|---|
| NIST SP 800-53 Rev 5 | IA-3 Device Identification and Authentication | Authenticating the server before the session is trusted |
| NIST SP 800-53 Rev 5 | SC-23 Session Authenticity; SC-8 Transmission Confidentiality and Integrity | Protecting the session against interception |
| NIST SP 800-53 Rev 5 | CM-3 Configuration Change Control | Rebuilds and key rotations recorded so warnings can be explained |
| NIST CSF 2.0 | PR.AA-03; PR.DS-02 | Hardware and services authenticated; data in transit protected |
| ISO/IEC 27001:2022 Annex A | A.8.20 Networks security; A.8.24 Use of cryptography | Secure remote administration and key handling |
| MITRE ATT&CK | T1557 Adversary-in-the-Middle; T1552.004 Private Keys; T1021.004 SSH | Interception, host key theft and SSH use for lateral movement |
Practitioner checklist
- Stop at the warning and record the file, line and new fingerprint.
- Find a documented reason: rebuild, IP reuse, load balancer, provider rotation or key type change.
- Get the expected fingerprint from a console, cloud boot log, published HTTPS list or DNSSEC-signed SSHFP.
- Compare the full fingerprint for the same key type before accepting.
- Remove only the affected entry with
ssh-keygen -R, after a backup. - Update global known_hosts files, images and pipeline pins that hold the old key.
- Escalate unexplained changes as possible interception and do not connect.
- Remove
StrictHostKeyChecking=nofrom scripts; use pinned keys oraccept-new. - Plan host certificates for any fleet rebuilt by automation.
Standards and references
- OpenBSD manual: ssh(1)
- OpenBSD manual: ssh_config(5)
- OpenBSD manual: sshd(8), SSH_KNOWN_HOSTS file format
- OpenBSD manual: ssh-keygen(1)
- OpenBSD manual: ssh-keyscan(1)
- IETF RFC 4255: Using DNS to Securely Publish SSH Key Fingerprints
- AWS: Amazon EC2 connection prerequisites, verifying the host key fingerprint
- GitHub Blog: We updated our RSA SSH host key
Related NHI Mgmt Group resources: OpenSSH Server Hardening Guide · SSH Permission Denied (publickey) Troubleshooting Guide · SSH Protocol and Certificate Authority Guide · Man-in-the-Middle Attacks Guide