Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to create a known_host entry but for some security ( permission ) reasons cannot add it directly when prompted for adding.

Are you sure you want to continue connecting (yes/no) --> cannot say Yes

Wondering if there is a way to generate the entry ( print on command line ), so I can put it manually in the known_hosts file. I have the RSA key fingerprint.

TO paraphrase the question can I specify my own known_host entry file to generate the above entry ?

Just fyi:- I also have access to ssh-keygen command, ssh-keyscan and others are not available. Please comment if above information is insufficient and I can answer

share|improve this question

migrated from Apr 24 '12 at 16:52

This question came from our site for professional and enthusiast programmers.

Have you tried fixing the permissions problem? What does 'ls-l ~/.ssh' say? – stinkymatt Apr 23 '12 at 21:24
Why can you not say Yes? Or rather, why do you think you can't? – ghoti Apr 23 '12 at 23:09
up vote 3 down vote accepted

You can use the -o switch to your ssh command to manually specify an alternative hosts file:

$ ssh -o UserKnownHostsFile=~/known_hosts.txt myserver

That will put the content into known_hosts.txt in your home directory, or you can change it to anywhere you should have write permissions to.

share|improve this answer

If you use this:

ssh -o StrictHostKeyChecking=no

you may be able to avoid the question altogether, but BEWARE, by doing this you are avoiding an important check that SSH uses to verify the identity of the remote host. You've mentioned that you have the RSA fingerprint. Check it, when using this option.

You asked how you might "generate" the entry that you'd add to your known_hosts file. I'll assume you're using OpenSSH.

On each of the servers you're connecting to, you'll need to find out where the remote host's SSH keys live. In Linux and FreeBSD, everything should be in /etc/ssh/. In OSX, the SSH configuration including keys are all right in /etc/. If you're not sure, you may be able to find the keys with:

find /etc/ -name ssh_host\*.pub -print

Most likely, you'll have results like this:


The content of these files on the remote servers can be added verbatim to the known_hosts file used by your ssh client. And obviously, if you normally use only one type of key, you probably don't need the contents of both files.

The other question you asked was whether it was possible to specify an alternate known_hosts file. The other answer to this question gives you instructions for that.

Note that you can also specify an alternate known_hosts file using an entry in your ~/.ssh/config file. For example:

host cloudhost*
    UserKnownHostsFile ~/.ssh/known_hosts_cloud

This might work for you if you collect all your host keys into the named file, and have hostnames like cloudhost1, cloudhost2, ... .

share|improve this answer
Do not suggest anyone to use StrictHostKeyChecking without explaining the security consequences. – Martin Prikryl Oct 1 '15 at 6:31
@MartinPrikryl ... Better? :) – ghoti Oct 1 '15 at 18:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .