The known_hosts file looks like this :-

[localhost]:8001 ssh-dss AAAAB3NzaC1kc3MAAACBAP1/U4EddRIpU   
[]:8001 ssh-dss AAAAB3NzaC1kc3MAAACBAP1/U4EddRIpUt9
// key are trimmed at the end

This keys are added via Eclipse IDE, Want to know what are other ways to add hosts (IPs) and their keys to ssh/known_hosts file.

Specific:- How to add ssh-dss key for any host(IP) in known_hosts file.


I am using JBoss BRMS which uses git for BRMS Projects, So at time of cloning the BRMS Project in Eclipse IDE via Git it gives following error

The authenticity of host 'localhost' can't be established.
DSA key fingerprint is e2:2c:62 //trimmed.
Are you sure you want to continue connecting?

And it then automatically add ssh-dss key to known_hosts file.

So where to find that key and add it manually on knownhosts file

  • Did you just post your private keys on the internet?
    – HackSlash
    Commented Dec 6, 2018 at 21:59
  • @HackSlash It is not private key and It is trimmed as you can see
    – Tarun
    Commented Dec 7, 2018 at 7:03
  • Similar question with complete answer here: stackoverflow.com/questions/34906302/… Safest is to get key out-of-band, generate the line and rehash. Commented Jul 9, 2023 at 17:32

3 Answers 3


The format of ~/.ssh/known_hosts is defined by OpenSSH. Other software might either call OpenSSH (the ssh command), or might have its own implementations that aren't necessarily 100% compatible.

The OpenSSH known_hosts format is described in the sshd(8) manual page, under "ssh_known_hosts file format". It says that it's a text file with one line per host–key pair:

Each line in these files contains the following fields: markers (optional), hostnames, keytype, base64-encoded key, comment. The fields are separated by spaces. […] Hostnames is a comma-separated list of patterns (‘*’ and ‘?’ act as wildcards); each pattern in turn is matched against the host name. […] A hostname or address may optionally be enclosed within ‘[’ and ‘]’ brackets then followed by ‘:’ and a non-standard port number.

To automatically add a key for a new host, just SSH to it.

To manually add a key for a new host, 1) open the known_hosts file in your text editor and 2) add the key for a new host, following the same format. (The key must match the host you're connecting to. You can query a host for its key using ssh-keyscan -t <type> <address>.)

To add a key for all hosts, use a * pattern as the hostname, which will match all hostnames and addresses. To add a key for all hosts on a specific port, use [*]:8001 as the hostname.

  • How to generate ssh-dss key for any host
    – Tarun
    Commented Dec 4, 2018 at 6:24
  • 1
    You don't generate it, you copy the key that the host already uses. There is no magic "any host" key. Commented Dec 4, 2018 at 6:29
  • i am using jboss EAP, a simple web application server which is running on localhost, where to find ssh-dss key ?
    – Tarun
    Commented Dec 4, 2018 at 7:16
  • 3
    If your app is running on localhost, then the SSH host itself is localhost. Use your own computer's key then, e.g. from ssh-keyscan -t dsa localhost. Commented Dec 4, 2018 at 7:47
  • i run this command on git bash on my computer Desktop. but it nothing is displaying on command line.
    – Tarun
    Commented Dec 4, 2018 at 8:40

For example you need to add to known_hosts:

ssh-keyscan -H >> ~/.ssh/known_hosts

For Docker file i use:

RUN apt-get update  \
    && apt-get install -y \
    ssh \
    && rm -rf /var/lib/apt/lists/* \
    && mkdir -p ~/.ssh/ \
    && ssh-keyscan -H >> ~/.ssh/known_hosts

Where apt-get install -y ssh - make possible use ssh-keyscan in command-line, then rm -rf /var/lib/apt/lists/* - cleanup downloaded package information with apt.


Try sshing into your target, and then type yes when it asks to save the key.

You must log in to answer this question.

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