使用 j2ssh maverick 在没有主机密钥验证的情况下连接到 ssh
Connect to ssh without Host Key Verification using j2ssh maverick
我有两台具有可信连接的服务器。我想在没有主机密钥验证的情况下通过 ssh 连接通过 SFTP 传输文件。
我正在使用 Java 1.7 和 Redhat Linux OS。
以前我使用的是 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 maverick 中实现这一点。
要在不验证主机密钥的情况下进行连接,您只需从 J2SSH Maverick 片段中删除以下代码
con.getContext().setHostKeyVerification(
new ConsoleKnownHostsKeyVerification());
但是,您要删除验证服务器的协议的重要部分。让您完全容易受到中间人攻击。
我有两台具有可信连接的服务器。我想在没有主机密钥验证的情况下通过 ssh 连接通过 SFTP 传输文件。
我正在使用 Java 1.7 和 Redhat Linux OS。
以前我使用的是 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 maverick 中实现这一点。
要在不验证主机密钥的情况下进行连接,您只需从 J2SSH Maverick 片段中删除以下代码
con.getContext().setHostKeyVerification(
new ConsoleKnownHostsKeyVerification());
但是,您要删除验证服务器的协议的重要部分。让您完全容易受到中间人攻击。