我尝试使用 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 设置为文件名,并将 Passphrase 设置为相关的 Passphrase。
我收到的提示是:
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 属性来删除它。 (当然没有成功)
有什么想法吗?
谢谢!
最佳答案
SshClient.connect 方法采用 HostKeyVerification 对象作为第二个参数,其中一个实现是 IgnoreHostKeyVerification,您可以像这样使用它:
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);
我不确定这是否能解决您的问题,但我认为可能就是这样。
关于java - 如何使用 sshtools SftpClient 和密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18430947/