![](/img/trans.png)
[英]timeout at net.schmizz.sshj.transport.KeyExchanger.waitForDone(KeyExchanger.java:160)
[英]net.schmizz.sshj.transport.TransportException: Unable to reach a settlement
我正在嘗試使用 SSHJ 將 ssh 連接到其他機器。 下面的 PFA 代碼(不包括 try/catch/finally 塊)。
Security.addProvider(new org.bouncycastle.jce.provider.BouncyCastleProvider());
final SSHClient sshClient = new SSHClient();
sshClient.addHostKeyVerifier(new PromiscuousVerifier());
sshClient.connect("test-hostname");
sshClient.authPublickey("test-user", private_key_path);
Session session = sshClient.startSession();
Session.Command cmd = session.exec(TEST_SSH_COMMAND);
cmd.join(5, TimeUnit.SECONDS);
if(cmd.getExitStatus() == 0) {
System.out.println("Success");
}
當我嘗試執行上述程序時出現以下錯誤
[reader] n.s.sshj.transport.TransportImpl - Dying because -net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [] and [aes128-ctr, aes192-ctr, aes256-ctr, arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, rijndael-cbc@lysator.liu.se]
2014-07-01 20:45:09,021 INFO [reader] n.s.sshj.transport.TransportImpl - Disconnected - UNKNOWN
2014-07-01 20:45:09,023 ERROR [pool-3-thread-1] net.schmizz.concurrent.Promise - <<kex done>> woke to: net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [] and [aes128-ctr, aes192-ctr, aes256-ctr, arcfour256, arcfour128, aes128-cbc, 3des-cbc, blowfish-cbc, cast128-cbc, aes192-cbc, aes256-cbc, arcfour, rijndael-cbc@lysator.liu.se]
2014-07-01 20:45:09,024 信息 [pool-3-thread-1] nssshj.transport.TransportImpl-斷開-BY_APPLICATION
有人可以幫我調試問題。
謝謝。
我遇到了同樣的問題,這是一個類加載問題。 另一個庫 (winzipaes) 依賴於另一個版本 auf Bouncycastle (bcprov-jdk16),該版本似乎與 SSHJ 引用的 jdk15 版本存在沖突。
明確排除 jdk16 版本對我有幫助(但是我還沒有測試使用 winzipaes 的代碼)。
我在部署 Cloudera 集群時遇到了同樣的問題。 確保受支持的MAC的客戶端和服務器集具有非空交集。
例如我得到:
net.schmizz.sshj.transport.TransportImpl: Dying because - net.schmizz.sshj.transport.TransportException: Unable to reach a settlement: [hmac-sha1, hmac-sha1-96, hmac-md5, hmac-md5-96] and [hmac-sha2-512-etm@openssh.com, hmac-sha2-256-etm@openssh.com, umac-128-etm@openssh.com, hmac-sha2-512, hmac-sha2-256, hmac-ripemd160]
解決方法是將至少一個客戶端 MAC 添加到服務器支持的 MAC。 在帶有SSH-2.0-OpenSSH_6.6.1p1 Ubuntu-2ubuntu2
Ubuntu 14.04.2 LTS 上,只需在/etc/ssh/sshd_config
編輯MACs
。
不太確定這里的安全含義,即某些方法可能會因為弱而被勸阻,但是您明白了,客戶端和服務器需要解決一個問題。 還要注意是客戶端做出選擇,服務器會適應。
不要忘記重新啟動服務器(如上的 Ubuntu): service ssh restart
。
我無法找到解決此問題的任何方法。 相反,我開始使用 JSch,現在它運行良好。
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
Session session = null;
ChannelExec channel = null;
try {
JSch jSch = new JSch();
jSch.addIdentity("/tmp/privatekey");
session = jSch.getSession("testuser", address, 22);
session.setConfig(config);
session.connect();
channel = (ChannelExec) session.openChannel("exec");
BufferedReader in = new BufferedReader(new InputStreamReader(channel.getInputStream()));
channel.setCommand(command);
channel.connect();
if (channel.getExitStatus() == 0 || channel.isClosed() || channel.isEOF()) {
logger.info("SSH connection is successful!");
}
in.close();
} catch (JSchException jsche) {
logger.error("Trying to SSH to host: {} but got exception {}", address, jsche);
} finally {
if (channel != null) channel.disconnect();
if (session != null) session.disconnect();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.