Verify host key in JSch with public key in “SSH2 P

2019-05-30 17:52发布

问题:

I am facing a problem with UnknownHostKey: servername, when trying to verify the host key using:

jsch.setKnownHosts("target/hostname_keys");

Is it possible to use hostkey file in SSH2 format that looks like this

---- BEGIN SSH2 PUBLIC KEY ----
AAAAB3NzaC1kc3MAAACBAKKQ7hwq7
.....
w5Uw==
---- END SSH2 PUBLIC KEY ----

with JSch?

Is there some good libraries that can work with SSH2 keys?

回答1:

JSch does not support public keys in this format.

But it's easy to convert that to known_hosts format.

Basically, just merge the lines into one and prepend a hostname:

example.com AAAAB3NzaC1kc3MAAACBAKKQ7hwq7...w5Uw==


标签: java ssh jsch