gpt4 book ai didi

fingerprint - 挣扎于 sshj 示例 ('exec' ) : Could not verify `ssh-rsa` host key with fingerprint

转载 作者:行者123 更新时间:2023-12-04 17:38:21 26 4
gpt4 key购买 nike

我正在尝试编写一个 java 程序,它将通过 ssh 连接并在工作的服务器上做一些事情(redhat linux)。我的盒子是 window 。我阅读了有关 sshj 的信息,并且正在尝试使示例起作用。我已经解决了大部分依赖项,现在我在处理公钥/私钥时出错,不幸的是我对那里也不太了解(是的,这是一场完美的新手 Storm !)。这是错误:

线程“main”net.schmizz.sshj.transport.TransportException 中的异常:[HOST_KEY_NOT_VERIFIABLE] 无法验证 ssh-rsa带指纹的主机 key 5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3dmyserver在端口 22

这是代码:

import net.schmizz.sshj.SSHClient;
import net.schmizz.sshj.common.IOUtils;
import net.schmizz.sshj.connection.channel.direct.Session;
import net.schmizz.sshj.connection.channel.direct.Session.Command;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

/** This examples demonstrates how a remote command can be executed. */
public class sshBuddy {

public static void main(String... args)
throws IOException {
final SSHClient ssh = new SSHClient();
ssh.loadKnownHosts();
//ssh.addHostKeyVerifier("5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3d");

ssh.connect("myserver");
try {
ssh.authPublickey(System.getProperty("myusername"));
final Session session = ssh.startSession();
try {
final Command cmd = session.exec("ping -c 1 google.com");
System.out.println(IOUtils.readFully(cmd.getInputStream()).toString());
cmd.join(5, TimeUnit.SECONDS);
System.out.println("\n** exit status: " + cmd.getExitStatus());
} finally {
session.close();
}
} finally {
ssh.disconnect();
}
}

}

任何帮助将不胜感激,谢谢!

最佳答案

试试这个

ssh.addHostKeyVerifier(new PromiscuousVerifier());

这应该有效

关于fingerprint - 挣扎于 sshj 示例 ('exec' ) : Could not verify `ssh-rsa` host key with fingerprint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10922292/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com