Pcornel
Browse topics
Options
Recent
Favorites
Linux · Technical reference

known_hosts

Direct answer

~/.ssh/known_hosts stores the host keys of servers you have connected to. ssh warns if a server presents a different key, which may mean reinstallation or a man-in-the-middle.

When to use this

Use it when ssh warns that a host key changed, or to pre-populate keys for automation.

First 30 seconds

1. Warning text: which host and key type?

2. Verify the server's real fingerprint (console: ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub).

3. Matches → ssh-keygen -R <host> and reconnect.

4. Does not match → stop and investigate.

5. Automation: pre-load with ssh-keyscan from a trusted network.

Operational verification

first connection stores the host key → later connections compare → match proceeds, mismatch warns

Evidence · next step

For SSH → known_hosts, continue with the first unproven Topic check: Identify the exact hostname/address/port form the client uses and which known_hosts files are active. If that boundary is healthy, advance to the adjacent check: Extract old and presented host-key fingerprints and verify the change through an independent trusted source. Preserve the same host/time/identity scope and rerun the original workload before accepting recovery.

Continue only after interpreting the current observation.
Context & applicabilityCommon mistakes · platform/version boundaries
Platform / version applicability
linux
applies
Structured applicability is explicit Topic metadata; it does not infer compatibility beyond the stored rows.
At a glance

Operational reference

Fast context before you go deeper.

Platformlinux
Scope / prerequisiteUse it when ssh warns that a host key changed, or to pre-populate keys for automation.
What next?3 suggested next steps
Evidence1
On this pageJump to a specific section
Operational workflow

Verification & Troubleshooting

Start with the observed symptom, prove the nearest boundary, and move outward only when the current state is understood.

5 steps Observe → verify → isolate → change minimally → repeat the original test.
ObservedRecord what the original test actually shows

Capture the concrete output, symptom, packet, log or counter before changing anything.

Step 1 Operational evidence path Verify boundary

destination name/address → known_hosts lookup → presented host key → fingerprint/trust decision → KEX continues → user authentication → session

Healthy evidence: the presented server key matches independently validated trust data for the intended endpoint and the client continues without unexpected identity warnings.

Step 2 Verification and output interpretation Verify boundary

Existing fast checks for this Topic. - Identify the exact hostname/address/port form the client uses and which known_hosts files are active.

  • Extract old and presented host-key fingerprints and verify the change through an independent trusted source.
  • Determine whether rotation, rebuild, address reuse, proxy/jump or load balancing explains the identity change.
  • Only then replace trust data and reconnect, confirming the expected server identity.

Verification chain. destination name/address → known_hosts lookup → presented host key → fingerprint/trust decision → KEX continues → user authentication → session

Step 3 Commands Verify boundary
ssh-keygen -F host
ssh-keygen -R host
ssh-keyscan host
Step 4 Failure modes and next checks Narrow the fault

Suspicious evidence: host-key changes are blindly removed, address reuse maps to another server, a proxy changes the observed endpoint or stale trust data blocks a legitimate but unverified rotation.

It does not show behavior outside the captured transport, trust, authentication, policy, session, filesystem or workload scope. known_hosts success shows client acceptance of the presented server identity according to local trust data, but it does not show the user account, server policy or application is healthy.

Step 5 Common mistakes Narrow the fault
  • Blindly removing changed host keys without checking why they changed.
Evidence references

Evidence · 1 on this Topic

Expected observations and documentation recipes are reference material. Record actual output, device identity, scope and time before claiming a verified result.

observation · 1
Key points

Verify a changed key through another channel before removing the old one (ssh-keygen -R <host>). Distribute known host keys centrally or use SSH certificates for many servers. StrictHostKeyChecking=no should not be used in production.

Key checks
  • ssh-keygen -F <host> — find a host's stored key
  • ssh -v user@host — client-side connection and authentication steps
  • journalctl -u ssh -u sshd -e — server log
  • sshd -T — effective server settings
  • ss -ltnp | grep :22 — sshd listening
ReferenceWhat it is1 section · depth on demand

Core model

Treat host-key mismatch as an identity event, not a nuisance prompt. Resolve which hostname/address entry matched, compare fingerprints through an independent trusted channel, account for legitimate rebuild/rotation/load-balancer cases, and update trust only after identity is established.

ReferenceImportant terms & boundaries5 sections · depth on demand

What this shows and what it does not

known_hosts success shows client acceptance of the presented server identity according to local trust data, but it does not show the user account, server policy or application is healthy.

known_hosts owns client-side server identity persistence.

In depth

known_hosts: trusting server keys

The client stores the host keys of servers it trusts in known_hosts. A key that differs from the stored one triggers the "REMOTE HOST IDENTIFICATION HAS CHANGED" warning. The sshd(8) manual page defines the file format:

  • Each line holds an optional marker, comma-separated host names, the key type, the base64 key and a comment.
  • Host names may use * and ? wildcards and ! negation. Non-standard ports are written as [host]:port.
  • Hashed names start with |, with one hashed name per line.
  • @cert-authority marks a CA key trusted to sign host certificates.
  • @revoked marks a key that must never be accepted.

Managing entries (ssh-keygen(1))

TaskCommand
Find entries for a hostssh-keygen -F srv1.example.net
Remove entries after a legitimate key changessh-keygen -R srv1.example.net
Hash existing names (keeps a .old copy)ssh-keygen -H
Show the server's own fingerprintssh-keygen -l -f /etc/ssh/ssh_host_ed25519_key.pub (on the server)

When the warning appears

SituationAction
The server was reinstalled or its keys regeneratedVerify the new fingerprint out of band, then ssh-keygen -R
An IP address was reused for another serverRemove the IP entry; prefer names
Nothing changed on the serverTreat it as a possible man-in-the-middle attack; don't connect

Host certificates instead of individual keys

With a host CA, one @cert-authority line covers all servers in a domain. Reinstalled servers then don't cause warnings, as long as their new key is signed.

admin$ ssh-keygen -F srv1.example.net
# Host srv1.example.net found: line 14
srv1.example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA...
admin$ ssh-keygen -R srv1.example.net
# Host srv1.example.net found: line 14
/home/admin/.ssh/known_hosts updated.
Original contents retained as /home/admin/.ssh/known_hosts.old
admin$ ssh-keyscan -t ed25519 srv1.example.net 2>/dev/null | ssh-keygen -l -f -
256 SHA256:pY3... srv1.example.net (ED25519)
admin$ grep '^@cert-authority' /etc/ssh/ssh_known_hosts
@cert-authority *.example.net ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAA... host-ca

Note on ssh-keyscan

ssh-keyscan fetches the key over the same network you're trying to verify, so it doesn't prove the key is genuine. Compare the fingerprint it shows with one obtained through a trusted channel.

Documented example, not captured output.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

How it works at runtime

known_hosts is part of SSH → known_hosts. known_hosts stores client-side SSH host identity bindings for hostnames/addresses and host keys (including hashed names and CA markers), allowing the client to detect unexpected server identity changes and resist machine-in-the-middle substitution.

Topic-specific state model. known_hosts stores client-side SSH host identity bindings for hostnames/addresses and host keys (including hashed names and CA markers), allowing the client to detect unexpected server identity changes and resist machine-in-the-middle substitution.

Technical metadata. Client host/distribution/OpenSSH version, server host/distribution/OpenSSH version, timestamp, destination name/address/port, source address, username, ssh_config Host/Match/Include resolution, proxy/jump path, negotiated KEX/host-key/cipher/MAC where relevant, server host-key fingerprint, known_hosts source, authentication method, client identity fingerprint/agent source, authorized-key source/options, sshd_config Include/Match/effective policy, PAM/account result, session type, PTY/command/subsystem, local/remote/dynamic forward endpoints, server PID/unit/listener, remote process/exit status, source/destination file path and hash where relevant, client/server logs and original workload result.

Interpretation rule. - Host-key warning ≠ safe to delete the entry automatically.

  • Same IP address ≠ same trusted SSH server identity over time.
  • DNS name resolves ≠ host key is authentic.
  • known_hosts entry matches ≠ user authentication or server authorization will succeed.

Quick reference

known_hosts records server host keys to detect impersonation (MITM).

ssh-keyscan -t ed25519 web01 >> ~/.ssh/known_hosts      # verify fingerprint out of band first
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub         # on the server
ssh-keygen -R web01                                      # remove after legitimate rekey/reinstall
ssh-keygen -F web01

"REMOTE HOST IDENTIFICATION HAS CHANGED" means the key differs: confirm the reason (rebuild, IP reuse) before removing the old entry. Publish host keys via SSHFP DNS records (VerifyHostKeyDNS yes) or host certificates to avoid manual trust.

Source basisSource attribution states what this section is based on; it is not independent proof that the current environment matches it.

Limits and how it fails

Primary failure point. known_hosts success shows client acceptance of the presented server identity according to local trust data, but it does not show the user account, server policy or application is healthy.

Possessing a private key does not guarantee the server accepts the key algorithm, maps the account or authorizes that public key. known_hosts protects server identity and is separate from user authentication. sshd_config syntax success does not show a safe remote reload.

ReferenceConfiguration & state1 section · depth on demand

Configuration, persistence and lifecycle

Distribution/platform context. known_hosts owns client-side server identity persistence. SSH Client owns verification behavior; DNS owns name resolution; PKI/TLS is separate from SSH host-key trust unless SSH certificates are explicitly used.

Additional reference context Scope · expected state · examples · history · terminology Open only when you need the supporting context
Technical verification history

Verification history & basis

When and against what this Topic was checked. Later text edits do not count as a new check.

2026-09-14 · vendor doclinux current

Authoritative/upstream documentation reviewed for bounded claims in SSH → known_hosts. Documentation verification only; this is not observed lab or production Evidence.

Basis: https://www.openssh.com/manual.html · confidence 94%
Technical changelog & impact

What changed and what may be affected

Recent technical edits are separated from ordinary page timestamps. Relationship impact is advisory: it identifies nearby canonical references to review, not automatic breakage.

Related reference impactReview these references after material technical changes when their shared boundary is affected.
Terminology layer

Terms & aliases

Hover a linked term for a quick definition; click it to open its glossary entry. Aliases are other names that find this Topic in search.

Aliases that resolve here
known_hostsssh host keyhost key verificationssh fingerprint mismatch
Embedded reference data

Quick lookup tables

known_hosts operational reference

Topic-specific lookup boundaries, proof limits and next-step Evidence for known_hosts.

Lookup boundaryTopic-specific referenceOperational use
Scope / effective stateknown_hosts stores client-side SSH host identity bindings for hostnames/addresses and host keys (including hashed names and CA markers), allowing the client to detect unexpected server identity changes and resist machine-in-the-middle substitution.Establish exactly what this Topic owns before crossing into another subsystem.
Fast verificationPin exact client/server + attempt time → resolve destination/TCP path → inspect effective client config → identify OpenSSH versions → verify KEX + host-key trust → trace offered/accepted authentication → inspect effective sshd policy for user/source → verify session/subsystem/forward → verify remote process/filesystem/service → repeat original workload.Use the shortest evidence path first; a fast check is a boundary test, not blanket proof.
Verification chaindestination name/address → known_hosts lookup → presented host key → fingerprint/trust decision → KEX continues → user authentication → sessionTrace requested/configured state through effective state to the observed workload result.
Failure boundaryknown_hosts success proves client acceptance of the presented server identity according to local trust data; it does not prove the user account, server policy or application is healthy.Stop broad troubleshooting at the first boundary that is not supported by evidence.
Positive evidenceCorrelated Linux SSH evidence can establish this proof path: destination name/address → known_hosts lookup → presented host key → fingerprint/trust decision → KEX continues → user authentication → sessionUse this observation only for the specific claim it actually supports.
Evidence limitIt does not independently prove behavior outside the captured transport, trust, authentication, policy, session, filesystem or workload scope. known_hosts success proves client acceptance of the presented server identity according to local trust data; it does not prove the user account, server policy or application is healthy.Do not promote a local success signal into end-to-end or adjacent-dependency proof.
Next troubleshooting checkContinue from the first unproven boundary: correlate client and server evidence for the same attempt, inspect effective client/server configuration and identity/trust/authentication state, then test the exact requested session, transfer or forward before changing additional layers.Continue to the next unresolved boundary while preserving the original test condition.

known_hosts · operational reference

Compact Linux state, persistence, verification and boundary reference for fast lookup.

Reference boundaryknown_hosts
Topic pathSSH → known_hosts
Runtime stateknown_hosts stores client-side SSH host identity bindings for hostnames/addresses and host keys (including hashed names and CA markers), allowing the client to detect unexpected server identity changes and resist machine-in-the-middle substitution.
Fast checks- Identify the exact hostname/address/port form the client uses and which known_hosts files are active. - Extract old and presented host-key fingerprints and verify the change through an independent trusted source. - Determine whether rotation, rebuild, address reuse, proxy/jump or load balancing explains the identity change. - Only then replace trust data and reconnect, confirming the expected server identity.
Verification chaindestination name/address → known_hosts lookup → presented host key → fingerprint/trust decision → KEX continues → user authentication → session Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return/regression → explicit Evidence boundary. Boundary chain: local authoritative state → adjacent dependency → effective/programmed state → original workload/request → return path or regression → explicit Evidence boundary.
Failure boundaryknown_hosts success proves client acceptance of the presented server identity according to local trust data; it does not prove the user account, server policy or application is healthy. Boundary chain: process/context → userspace configuration → kernel subsystem/resource → device/network/filesystem dependency → effective state → original workload.
Persistence ruleProve which configuration source owns the state, then prove that the running consumer loaded or generated the intended state.
Confirmation

Confirm action

Continue?