Menu ▾ ▴

#61 "com.jcraft.jsch.JSchException: UnknownHostKey exception" but key exists in /etc/ssh/ssh_known_hosts

v1.0 (example)
open
nobody
None
5
2015-03-26
2013-06-11
No

com.jcraft.jsch.JSchException: UnknownHostKey exception is thrown when host key is not included in ~/.ssh/known_hosts

However, the host key is included in /etc/ssh/ssh_known_hosts file, which should also be checked. (the OpenSSH 'ssh' program also reads this file)

Discussion

  • Anonymous

    Anonymous - 2015-03-04

    Just ran into this today with the gradle ssh plugin: https://github.com/int128/gradle-ssh-plugin/issues/151

    Kind of disappointing that it's such an old bug, maybe it's easy to fix.

     
  • Paul Campbell

    Paul Campbell - 2015-03-26

    It looks like Jsch is expecting ~/.ssh/known_hosts to be in a different format.

    The output of ssh-keyscan -t rsa hostname is what it expects. e.g.:

    hostname ssh-rsa AAAAB.......
    

    However, that isn't the format of my file. i.e.:

    |1|3pt63YCQENNi57rjdlw.......
    

    What this new format is, I don't know. It doesn't contain the hostname, at least not in clear text.

    A workaround for me has been to add the appropriate entry to known_hosts in the expected format:

    ssh-keyscan -t rsa hostname >> ~/.ssh/known_hosts
    
     

Log in to post a comment.