rescueshell Start trial

SSH "Failed to add the host to the list of known hosts"

This line means ssh tried to record a host key in a known_hosts file and could not write it there. It comes from the machine you typed the command on, and the file it names is on that machine too. It is about saving the key, not about whether the host or its key is right.

This page describes standard OpenSSH behaviour. The commands are the usual ones, and wording differs between versions, distributions and platforms. We did not run them on your system for this page.

What the line looks like

Failed to add the host to the list of known hosts (PATH).

The full stop is part of the line, and ssh fills in PATH with the file it tried to update. A made-up example:

Failed to add the host to the list of known hosts (/home/you/.ssh/known_hosts).

The line does not say why the write failed. Several different problems with that file or its folder can look alike from here, so this page does not list causes. It shows how to look at the file the line names.

Which page is this?

1. Confirm the line

Run the same command again with -v and read the whole output, not only the last line.

ssh -v user@server.example.com

The ssh -v output reader can check a pasted log for this line and shows the path it names. It runs in your browser and sends nothing.

This page is about a line ssh could not write. If you already have a line and want to see what kind it is and which field is wrong, the known_hosts and authorized_keys line checker reads it in your browser and sends nothing.

2. Cheap checks that are not a diagnosis

Each of these is quick and none of them is certain for your machine. Start with the path in the line, not with the usual ~/.ssh/known_hosts, because the file named may be a different one.

Read the path

Copy PATH from the line. If it is not the file you expected, a setting or an option on the command line may be pointing ssh somewhere else, and that is the file to check.

Can this account create or write that file?

List the file with its owner and mode, using the path from the line:

ls -l /home/you/.ssh/known_hosts
id -un

If the file exists, check that its owner is the account running ssh and that this account can write it. If it does not exist, ssh needs to be able to create it, which depends on the folder.

Is the folder there?

ls -ld /home/you/.ssh

Check that the folder in the path exists and that this account can write in it. A read-only file system, a full disk, a locked-down container or a shared home directory can all look the same as the checks above; the line does not tell you which, and wording and behaviour differ between versions and platforms.

If you change an owner or a mode, change only the file or folder the line names. Do not delete the whole file to make the line go away: it holds the recorded keys that protect hosts you have already checked.

3. Retry the same command

After you change one thing, run the same ssh command again. If the write now works, you should see the Warning: Permanently added line, or no line at all if the key is already stored. If the same line comes back, check the path again, since it may have named a different file this time. If a different message follows, one of the pages above covers it.

If the machine is a RescueShell device

This line is about a known_hosts file on the machine running ssh, and the relay does not write that file. RescueShell does not use this prompt for the device: the first time a browser connects to a device, the page asks you to check the device's fingerprint once. A path that starts from the device can also avoid a public SSH port, because the agent keeps an outbound HTTPS connection to our relay. See SSH behind a firewall without port forwarding. If a shell does not open once the agent is installed, see the shell does not open.

Try it on one device

The first device is free to try with no card, for 30 days from when it connects, not from when you sign up. Start a trial.