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.
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.
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.
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.