"com.jcraft.jsch.JSchException: UnknownHostKey exception" but key exists in...
Status: Alpha
Brought to you by:
ymnk
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)
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.
It looks like Jsch is expecting
~/.ssh/known_hoststo be in a different format.The output of
ssh-keyscan -t rsa hostnameis what it expects. e.g.:However, that isn't the format of my file. i.e.:
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_hostsin the expected format: