JSch和RebexTinySftpServer:测试SSH连接上的已知主机功能

时间:2017-07-15 09:54:36

标签: java ssh server jsch

我想在JSch中测试已知的主机功能(www.jcraft.com/jsch/最新版本)

Test Server正在监听这样的连接:0.0.0.0:22

我这样连接(ipAdress和端口是localhost和22):

    JSch jsch = new JSch();
    this.session = jsch.getSession(this.properties.getUserName(), this.properties.getIpAddress(),
        this.properties.getPortNumber());

    String hostKey = "localhost,[0.0.0.0]:22,128.0.0.1 aes256-cbc AAAAB3NzaC1yc2EAAAADAQABAAABAQCCzaF8d0IGrjNqm+1wKcYIQCs8obYepgSpQCrONrR1CJ1hLh5tNTgEedsWfTvSoigjRRm/QtKV7uUIPCjBa+YrHfqmMOYxHi6yyEZd7TUS9a19tkph1A0EwnpQS7Ss88H3AGElAe56SaIW7mlQCWo86MdfejZBHtVFPaOUdtyRXeAPCLXzuVWIBgFh96OwFq80TyF1gE2d+l5NyPd4qgwhO+XeZXC2ZZ/KiuGSCftaIMmOxZfBDfLpqDm3Nr0KJtuDMI2vAYt+pWdIXpxx5LpYxQbHtsqhHv0A3zBTNqqR/TaPWhudf1ohflU2cYaXFAZu5lgLPBE0ZuCRkvTxW6Pn";
    jsch.setKnownHosts(new ByteArrayInputStream(hostKey.getBytes()));
    jsch.addIdentity(this.properties.getKeyFile());
    this.session.connect();
    this.channel = this.session.openChannel("sftp");
    this.channel.connect();
    this.channelSftp = ((ChannelSftp) this.channel);

服务器密钥如下所示:

PuTTY-User-Key-File-2: ssh-rsa
Encryption: aes256-cbc
Comment: ssh-rsa-key-20170614
Public-Lines: 6
AAAAB3NzaC1yc2EAAAADAQABAAABAQCCzaF8d0IGrjNqm+1wKcYIQCs8obYepgSp
QCrONrR1CJ1hLh5tNTgEedsWfTvSoigjRRm/QtKV7uUIPCjBa+YrHfqmMOYxHi6y
yEZd7TUS9a19tkph1A0EwnpQS7Ss88H3AGElAe56SaIW7mlQCWo86MdfejZBHtVF
PaOUdtyRXeAPCLXzuVWIBgFh96OwFq80TyF1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b1a8db2dd67b2b9c15bc15

与服务器的连接有效;只有当我启用严格的主机已知检查时,我才能让它工作......

我错过了什么?

感谢您的帮助

0 个答案:

没有答案