我有两个连接可信的服务器。我想通过SFTP传输文件,通过ssh连接,没有主机密钥验证。
我正在使用Java1.7和Redhat Linux操作系统。
以前,我使用j2ssh-core0.2.9.jar连接到ssh,如下所示:
SshConnectionProperties properties = new SshConnectionProperties();
SshClient ssh = new SshClient();
properties.setHost(host);
properties.setPort(port);
ssh.setSocketTimeout(readTimeOut);
ssh.connect(properties,new IgnoreHostKeyVerification()); 在j2ssh特立独行,
SshConnector con = SshConnector.createInstance();
con.getContext().setHostKeyVerification(
new ConsoleKnownHostsKeyVerification());
con.getContext().setPreferredPublicKey(
Ssh2Context.PUBLIC_KEY_SSHDSS);
SocketTransport t = new SocketTransport(hostname, port);
t.setTcpNoDelay(true);
SshClient ssh = con.connect(t, username);
Ssh2Client ssh2 = (Ssh2Client) ssh;请建议如何在j2ssh中实现这一点。
发布于 2015-09-11 17:58:17
要在没有主机密钥验证的情况下进行连接,只需从J2SSH Maverick代码段中删除以下代码
con.getContext().setHostKeyVerification(
new ConsoleKnownHostsKeyVerification());但是,您正在删除协议中对服务器进行身份验证的重要部分。让你完全接受中间人的攻击。
https://stackoverflow.com/questions/32522183
复制相似问题