Thanks for the response.
If my known hosts file already has the host key of the remote machine, my connection code works fine. If not, then it doesn't work.
My code does the following (high level)
* setKnownHosts (to my known hosts file)
* Session session = jsch.getSession(user, host, 22);
In case of an exception (UnknownHostKey), I do this:
HostKey hk = session.getHostKey();
HostKeyRepository repo = jsch.getHostKeyRepository();
Throws a NullPointerException as hk is null. (This makes sense as the session might not have the required info.) How can I get the host key of the remote machine and add it?
+-From: Manikandan Chandrasekaran <firstname.lastname@example.org> --
|_Date: Wed, 22 Sep 2010 15:25:32 +0530 ____________________________
|Try and refer to
|This is what I would like to do..
|* I get the details of the machine to which I have to make a connection
|* session.connect() throws a JschException
|* Prompt the user whether to accept the fingerprint or not. If no, exit.
|* Add the host key to the known hosts
|* I'll do session.connect() again
|I am stuck at the place where I can add the key to the known hosts.. Can
1-14-20 HONCHO AOBA-KU,
SENDAI, MIYAGI 980-0014 Japan.