Skip to main content
Imagine you connect to a production server and suddenly see: warning, remote host identification has changed. Is this a legitimate change or a security risk? Or maybe you’re still using passwords for SSH, which isn’t secure or scalable. This article answers those questions. It explains SSH host keys and server identity verification, shows how to configure key-based authentication (replacing passwords with cryptographic keys), and describes secure file transfer using SSH-based tools. Together these topics move you from simply using SSH to managing it safely in production environments.
A dark-themed slide titled "Overview" with three bullet points about SSH: understanding host keys and server identity verification, configuring SSH key-based authentication, and transferring files securely using SSH tools. The layout shows the title on the left and the bullets on the right.
Why host keys matter SSH uses public-key cryptography to ensure the server you connect to is the server you expect. On first connection, a server presents its public host key; the client records that key in ~/.ssh/known_hosts. On subsequent connections the client verifies the presented host key against the stored entry. If the key matches, the connection proceeds; if it differs or is unknown, SSH raises a warning so you can decide how to proceed. This prevents accidental connections to the wrong machine and defends against man‑in‑the‑middle attacks.
A dark-themed flowchart showing the SSH connection process: a client connects to a server and exchanges a public key, which is checked against known_hosts. If the key matches the decision leads to "Connection established"; if not, "SSH raises a warning."
StrictHostKeyChecking — client-side host key policy The StrictHostKeyChecking option controls how the SSH client handles unknown or changed host keys. Choosing the right policy balances security and automation.
A dark-themed slide showing a table titled "Strict Host Key Checking on Clients" that lists SSH options (yes, accept-new, no, ask) with short descriptions of how SSH handles server host keys and the known_hosts file.
Practical admin tasks with host keys Common administrative activities when managing host keys:
  • Verify a server’s host key fingerprint manually with ssh-keygen -l -f /path/to/key.
  • Regenerate host keys after reinstalling or cloning a server.
  • Use ssh-keyscan to collect public keys and pre-populate known_hosts for automation and fleet management.
  • Remove or replace stale known_hosts entries with ssh-keygen -R <host>.
Use ssh-keyscan to seed known_hosts in automated deployments and prefer accept-new over no when you need automation with some safety.
Demo: exploring host keys and client behavior The following walkthrough shows a typical sequence of actions on a control node (client) and a server (node1). The examples illustrate how host keys are added to the client, where host keys live on the server, how to regenerate them, and how the client responds when the server’s host key changes.
  1. First SSH connection from control to node1 — the client prompts to accept the host key, then asks for a password:
After login, exit back to the control node and inspect ~/.ssh/known_hosts — it now contains the host entries for node1:
  1. On the server (node1), host keys live under /etc/ssh. List them to view the server’s identity files:
  1. If host key files are removed, regenerate them on the server and restart sshd:
  1. Back on the control node, attempting to connect now shows a host key mismatch because the server presents new keys that differ from ~/.ssh/known_hosts:
To resolve, remove or update the old node1 entry in ~/.ssh/known_hosts. The ssh-keygen -R command removes the specified host entry:
  1. How StrictHostKeyChecking changes the connection behavior
  • With strict checking enabled (StrictHostKeyChecking=yes), SSH refuses to connect to hosts with unknown keys:
  • With strict checking disabled (StrictHostKeyChecking=no), SSH automatically accepts and adds the host key and continues the connection (convenient but less secure):
Note that accept-new is generally safer for automated tasks than no because it only auto-accepts keys that are truly new and still rejects changed (potentially malicious) keys.
Disabling host key verification (StrictHostKeyChecking=no) is convenient for scripts and automation, but it makes you vulnerable to man‑in‑the‑middle attacks. Use it only in controlled environments and prefer ssh-keyscan to pre-populate known_hosts where possible.
Useful commands reference Summary
  • SSH host keys are how servers prove identity; clients store trusted host keys in ~/.ssh/known_hosts.
  • StrictHostKeyChecking defines how the client treats unknown or changed keys — choose policies based on risk and automation needs.
  • Regenerate server host keys with sudo ssh-keygen -A and restart sshd when necessary.
  • Use ssh-keyscan to safely seed known_hosts in automated deployments and ssh-keygen -l to verify fingerprints manually.
  • Avoid disabling strict host key checking in production; prefer accept-new or pre-populating known_hosts for automation.
Links and references

Watch Video