2013-08-25 25 views
1

我正在嘗試使用j2ssh SshClient而沒有成功。如何在密碼中使用sshtools SftpClient?

我正在嘗試使用專用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設置爲相關密碼。

別的東西,我得到的提示:

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] 

,我有嘗試使用StrictHostKeyChecking屬性設置爲「無」來刪除。 (當然沒有成功)

任何想法??

謝謝!

回答

2

的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); 

我不知道這是否解決您的問題,但我認爲它可能是它。

相關問題