Join our Newsletter — 33% off our NHI Course
Home› Guides› What to do when SSH warns REMOTE HOST…
Guide Secrets Management

What to do when SSH warns REMOTE HOST IDENTIFICATION HAS CHANGED: verify the new key before you trust it

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 15 November 2026 13 min read
On this page

"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 ask setting 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 host removes 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 and accept-new only 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 valueNew, unknown hostChanged key for a known hostWhere it fits
ask (default)Added only after you confirmRefusedInteractive use
yesNever added automaticallyRefusedAutomation with pre-distributed keys or host certificates
accept-newAdded automaticallyRefusedPipelines where first-use trust is accepted but changes must stop the job
no or offAdded automaticallyAllowed, subject to some restrictionsAvoid; 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.

  1. 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.
  2. Is the name or IP now a different machine? Cloud IP addresses and DHCP leases are reused. An entry for 10.0.4.17 may refer to an instance destroyed last month.
  3. 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.
  4. 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.
  5. 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.
  6. 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.

CauseTypical signsSafe response
Server rebuilt or reimagedChange ticket exists; owner confirmsVerify new fingerprint from the console, replace entry
IP or name reusedEntry is by IP; host was recently recreatedVerify, replace entry; prefer names or HostKeyAlias over raw IPs
Load balancer or round robinWarning comes and goes for one nameGive each backend the same host certificate or a stable alias per host
Provider key rotationPublic announcement; many users affected at onceCheck the provider's published fingerprints over HTTPS, replace entry
Key type change after upgradeWarning names a different algorithmVerify the fingerprint for that type, then replace
InterceptionNo change explains it; untrusted network; other hosts affectedDo 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 truthHow to get the fingerprintNotes
Server consoleHypervisor, out-of-band management or physical console; run ssh-keygen -l -f on each .pub host key fileStrongest check for servers you own
Cloud boot logAmazon EC2: "Get system log" or aws ec2 get-console-output, then read between BEGIN SSH HOST KEY FINGERPRINTS and END SSH HOST KEY FINGERPRINTSAvailable after first boot; AWS notes output varies by operating system and AMI
Published provider listProvider 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 recordsVerifyHostKeyDNS=yes with records generated by ssh-keygen -rRFC 4255 says a key verified this way must not be trusted unless the record is DNSSEC-authenticated
Configuration managementFingerprints recorded when the host was built, in an inventory or CMDB you trustOnly 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

  1. Record the evidence: copy the warning text, including the old file and line number and the new fingerprint.
  2. Look before you remove: ssh-keygen -F hostname lists matching entries, including hashed ones, and works with [hostname]:port for non-standard ports.
  3. Back up the file: copy ~/.ssh/known_hosts before editing.
  4. Remove the old keys for that host: ssh-keygen -R hostname (and again for the IP address if CheckHostIP stored 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.
  5. 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.
  6. 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-new for 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/checkout with the ssh-key option 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 KnownHostsCommand for 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

ApproachHow it worksBest forTrade-off
Host certificatesClients trust a CA through an @cert-authority line; rebuilt hosts get a new signed certificateMedium and large fleets, autoscalingCA key must be protected and signing automated
Managed global known_hosts/etc/ssh/ssh_known_hosts distributed by configuration managementStable server estatesEvery rebuild needs a file update
Preserve host keys on rebuildRestore the original host key files from a secrets store to the new instanceLong-lived names with planned rebuildsHost private keys become secrets to manage and rotate
UpdateHostKeysClient learns extra keys a trusted server offers, easing planned rotationRotating to a new algorithmOnly for hosts already verified in the user known_hosts file, OpenSSH 6.8 or later servers
SSHFP with DNSSECFingerprints published in signed DNS, checked with VerifyHostKeyDNSOrganisations already running DNSSEC validationWithout 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=no or UserKnownHostsFile=/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=no lives on in pipelines for years.
  • Verifying against the suspect connection. Running ssh-keyscan from 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

FrameworkReferenceRelevance
NIST SP 800-53 Rev 5IA-3 Device Identification and AuthenticationAuthenticating the server before the session is trusted
NIST SP 800-53 Rev 5SC-23 Session Authenticity; SC-8 Transmission Confidentiality and IntegrityProtecting the session against interception
NIST SP 800-53 Rev 5CM-3 Configuration Change ControlRebuilds and key rotations recorded so warnings can be explained
NIST CSF 2.0PR.AA-03; PR.DS-02Hardware and services authenticated; data in transit protected
ISO/IEC 27001:2022 Annex AA.8.20 Networks security; A.8.24 Use of cryptographySecure remote administration and key handling
MITRE ATT&CKT1557 Adversary-in-the-Middle; T1552.004 Private Keys; T1021.004 SSHInterception, 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=no from scripts; use pinned keys or accept-new.
  • Plan host certificates for any fleet rebuilt by automation.

Standards and references

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

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 15 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.