Skip to content
BENIBIX Learn

known_hosts

Infrastructure🔑 SSH & Remote AccessSSH Basics

Also known as known_hosts File, ~/.ssh/known_hosts, Known Hosts

A file on your computer with each server's key. SSH uses it to spot a fake.

Think of it like

Think of it like a guest book of faces. Next time someone comes, you check the book.

Example

Emma's server was rebuilt on purpose. She removes its old line with ssh-keygen -R, then logs in and trusts the new key.

Why it matters

It is your memory of which servers are real. Without it, SSH could not warn you about a fake.

Definition

known_hosts is a file on your own computer that lists the servers you trust. It sits at ~/.ssh/known_hosts. Each line holds a server's address and its host key. SSH adds a line the first time you say yes to a new server. On later logins it checks the key against this line.

Example code

console
$ ssh-keygen -R 203.0.113.10
# Host 203.0.113.10 found: line 4
/home/emma/.ssh/known_hosts updated.
Remove the old key for one server. The next login asks you to trust the new one.
The saved list on the laptop is known_hosts. Each visit is checked against it.

Common mistake

Deleting the whole file to stop a warning. That throws away every saved key, not just the one that changed.

Key takeaways

  1. 1
    Your side. Lives in your .ssh folder.
  2. 2
    One line per server. Address and host key.
  3. 3
    Remove one line. Use ssh-keygen -R.

Compare

Learn it properly