Here is the format I found that works with later versions of jch:
[xx.xx.xx.xx]:22 ssh-rsa .......
In older versions, it looked like:
xx.xx.xx.xx ssh-rsa ......
i.e. no square brackets and port numbers. (Not sure if the port number is needed if you are using port 22, but I tested it with a server with a port other than the standard for SSH, and, if this is not obvious, xx.xx.xx.xx should be the IP address of the server or hostname or something else.)
I found this format by getting the JCraft / jsch library to create the known_hosts file for me. If you visit www.jcraft.com , you can download the jsch source code zip and some examples. Either create a source to make a jar, or load a ready-made jar. I unzipped the zip download and then spat the jar file in the same directory.
Here is the examples folder containing KnownHosts.java . You need to compile this file and then run it - it will ask you about your known_hosts file (first create an empty file in the default location ( ~/.ssh/known_hosts ) and then ask it to find out how to connect to the server ... Enter those, for example sshusername@xx.xx.xx.xx , and the program will try to connect, and then fill out the known_hosts file for you.
For convenience for Windows users like me, who never remember how to do things from the command line, here is what you need to compile and run this KnownHosts.java file:
First go to the directory (unzip it and put the jar file inside as described above).
Then run:
javac -cp jsch-0.1.49.jar examples/KnownHosts.java
to compile KnownHosts.java. And then:
java -cp "examples;jsch-0.1.49.jar" KnownHosts
to run it. Follow the instructions above and you should have a known_hosts working file.
One final note: KnownHosts assumes port 22. I edited it to allow me to enter something like sshusername@xx.xx.xx.xx :8888 so that I could specify a server with a custom port and make it work as described above. In the source of KnownHosts.java, I searched for a line like:
Session session=jsch.getSession(user, host, 22);
and replaced it with:
int port = 22; final int colonIndex = host.indexOf(':'); if (colonIndex > -1) { final String[] split = host.split(":"); host = split[0]; port = Integer.parseInt(split[1]); } Session session=jsch.getSession(user, host, port);
and then compiled and works as above.