2011-03-16 40 views

回答

2

在SSH,還有一個配置選項:

StrictHostKeyChecking=no 

你或許可以設置這j2ssh這樣的:

setConfig("StrictHostKeyChecking", "no") 

這是否是一個好主意,留下作爲一個練習讀者。

+0

@Johnsweb我使用java和ssh = new SshClient(); ssh。(方法沒有.setConfig(string?!,string);)現在如果這是一個好主意? 2選項,因爲即時通訊創建應用程序/ exe文件,如果我使用這個驗證用戶可以自動登錄;但否則安全性可能會受到影響:D – user615927 2011-03-16 10:05:51

+0

很好解決了這個問題,但是在一個非常奇怪的情況下,可能無效的方式從[here](http://angelborroy.wordpress.com/2008/07/28/ftps-in-java) /)然後ssh.connect(「127.0.0.1」,22,new AlwaysAllowingConsoleKnownHostsKeyVerification()); – user615927 2011-03-16 10:25:37

+0

@ user615927:您通過SSH連接到* localhost *? – Johnsyweb 2011-03-16 10:33:03

2

如果你不想驗證主機,下面的代碼段應該做的工作:

ssh.connect(hostname, new IgnoreHostKeyVerification()); 
0

這裏是一個片段,剛從例如here更換零件。

SshClient ssh = new SshClient(); 
    ssh.setSocketTimeout(30000); 
    SshConnectionProperties props = new SshConnectionProperties(); 
    props.setHost(hostname); 
    props.setPort(port); 
    ssh.connect(props , new IgnoreHostKeyVerification()); // ignore unknown host warning 
    // Create a password authentication instance 
    PasswordAuthenticationClient pwd = new PasswordAuthenticationClient(); 
    pwd.setUsername(username); 
    pwd.setPassword(password);  
    // Try the authentication 
    int result = ssh.authenticate(pwd); 
相關問題