我正在尝试写一个java程序,它将通过ssh连接,并在工作中的服务器(redhat linux)上做一些事情。我的盒子是窗户。我读到了关于sshj的文章,我正在尝试让这个例子起作用。我已经处理了大多数依赖项,现在我在处理公钥/私钥时遇到了错误,不幸的是,我也不太了解这些(是的,这是一场完美的新手风暴!)下面是错误:
线程"main“中出现异常,net.schmizz.sshj.transport.TransportException: HOST_KEY_NOT_VERIFIABLE无法使用端口22上myserver的指纹5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3d验证ssh-rsa主机密钥
代码如下:
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();
}
}
}如有任何帮助,将不胜感激,谢谢!
发布于 2014-09-24 16:22:37
试试看这个
ssh.addHostKeyVerifier(new PromiscuousVerifier());这应该是可行的
发布于 2012-07-11 19:10:28
尝尝这个
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();
}
}
}取消注释addHostKeyVerifier并注释loadKnownHosts。应该能行得通。
发布于 2019-11-01 06:21:10
这应该是可行的:
ssh.addHostKeyVerifier("MD5:5f:d6:94:00:9e:ec:7e:34:6d:d0:d3:76:df:5e:dd:3d")方法addHostKeyVerifier可以接收最终字符串作为参数,该字符串用于在FingerprintVerifier.java类中执行验证。
根据the repo的说法,可以使用其他输入,例如:
"SHA1:2Fo8c/96zv32xc8GZWbOGYOlRak=""SHA256:oQGbQTujGeNIgh0ONthcEpA/BHxtt3rcYY+NxXTxQjs=""MD5:d3:5e:40:72:db:08:f1:6d:0c:d7:6d:35:0d:ba:7c:32""d3:5e:40:72:db:08:f1:6d:0c:d7:6d:35:0d:ba:7c:32"如果有多个密钥,请仔细检查ssh服务器的默认公钥的指纹。
https://stackoverflow.com/questions/10922292
复制相似问题