1

我正在尝试使用 j2ssh SshClient 但没有成功。

我正在尝试使用私有 RSA 密钥 + 密码打开连接。我发现了一些我不确定是写方法的东西:

Properties properties = new Properties();
properties.put("Passphrase", "xyz");
properties.put("PrivateKey", "sftp_rsa");
properties.put("Username", "user");
properties.put("StrictHostKeyChecking", "no");
publicKeyAuthenticationClient.setPersistableProperties(properties);
int result = ssh.authenticate(publicKeyAuthenticationClient);

我正在使用 setPersistableProperties 方法来加载保存相关数据的 Properties 对象。我已将 PrivateKey 设置为文件名,并将密码短语设置为相关的密码短语。

别的东西是我得到一个提示:

The host hostname.host,1.1.1.1 is currently unknown to the system
The host key fingerprint is: 100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Always option disabled, host file is not writeable
Do you want to allow this host key? [Yes|No]

我尝试使用设置为“no”的 StrictHostKeyChecking 属性来删除它。(当然没有成功)

任何想法??

谢谢!

4

1 回答 1

2

the SshClient.connect method takes an HostKeyVerification object as the second argument, one of the implementations is IgnoreHostKeyVerification, you can use it like:

SshConnectionProperties props = new SshConnectionProperties();
props .setHost(server);
props .setPort(port);
sshClient.connect(props , new IgnoreHostKeyVerification());

//this is your code
Properties properties = new Properties();
properties.put("Passphrase", "xyz");
properties.put("PrivateKey", "sftp_rsa");
properties.put("Username", "user");
properties.put("StrictHostKeyChecking", "no");
publicKeyAuthenticationClient.setPersistableProperties(properties);
int result = sshClient.authenticate(publicKeyAuthenticationClient);

i am not sure if this fix your issue but i think it might be it.

于 2013-09-16T09:38:38.990 回答