Skip to content
BENIBIX Learn

known_hosts vs authorized_keys

People often think both files hold the same keys. They face opposite ways. known_hosts is on your computer and lists the servers you trust. authorized_keys is on the server and lists the people it lets in. One proves the server to you, the other proves you to the server.

Infrastructure🔑 SSH & Remote Access

known_hosts

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

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
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.
Full entry
Infrastructure🔑 SSH & Remote Access

authorized_keys

A file on the server. It lists the public keys that may log in as that user.

authorized_keys is a file on the server that lists the public keys allowed to log in. It sits in the .ssh folder of the user's home. Each line is one public key. The ssh-copy-id command adds your key to it for you. SSH ignores the file if its rights let other users change it.

Example
Jack joins Lucy's team. Lucy adds Jack's public key as a new line in authorized_keys, and Jack can log in.
Why it matters
It is the guest list for the server. Removing a line is how you take someone's access away.
Full entry

In one line

known_hosts
A file on your computer with each server's key. SSH uses it to spot a fake.
authorized_keys
A file on the server. It lists the public keys that may log in as that user.