SSH "Warning: Permanently added ... to the list of known hosts": what it means
ssh prints this when it saves a new host key to known_hosts. Seeing it on every connection means the key is not being saved. How to fix that or hide it.
The first time you connect to a host, OpenSSH may print:
Warning: Permanently added 'host.example.com' (ED25519) to the list of known hosts.
Despite the word "Warning", nothing is wrong. ssh has just saved the host's key to your known_hosts file, so that it can check the key on every later connection. The part in brackets is the key type.
For a server on a port other than 22, the name is saved with the port: '[host.example.com]:2222'.
When it appears
ssh saves a new host key, and prints this line, when:
- you answer
yestoAre you sure you want to continue connecting (yes/no/[fingerprint])?, or StrictHostKeyCheckingis set toaccept-new(adds new keys without asking, still refuses changed ones) orno(adds new keys and lets connections to hosts with changed keys go ahead, with some limits).
On the next connection the key is already there, and the line does not appear again. To check the key you accepted, see Known hosts and fingerprints.
Seen on every connection
If the line comes back each time, the key is not being kept. Look for one of these:
UserKnownHostsFile /dev/nullin the command, in~/.ssh/configor in a script's options. Every key is "saved" into nothing, so every connection is a first connection. This is common in scripts and in instructions for throwaway test machines.- A known_hosts file that cannot be written. ssh then says
Failed to add the host to the list of known hosts (/home/user1/.ssh/known_hosts).instead. Check the ownership and permissions of~/.sshand the file. - A different home folder or user each time, for example a tool that runs ssh as another user or in a fresh container.
Hide the line
The message is logged at ssh's normal level, INFO. To hide it for one host without changing anything else about host keys:
Host build-box
HostName host.example.com
LogLevel ERROR
LogLevel ERROR also hides other informational lines, so use it only where you do not need them. The default is INFO.
known_hosts entries look scrambled
On Debian and Ubuntu, the client's default /etc/ssh/ssh_config sets HashKnownHosts yes, so new entries are saved as |1|... hashes instead of names. To find or remove one, see Hashed known_hosts: find, remove or hash hosts with ssh-keygen.
If ssh refuses to connect because the saved key no longer matches, that is a different message: see Read the SSH warning "REMOTE HOST IDENTIFICATION HAS CHANGED".
Related
- Known hosts and fingerprints
- Hashed known_hosts: find, remove or hash hosts with ssh-keygen
- The ssh config file