我正在开发java程序,以便通过ssh与windows服务器连接。为此,我在java上使用了jcraft。而ssh服务器是copSSH。实现抛出
错误: com.jcraft.jsch.JSchException:算法协商失败
java错误。同时,它显示
致命:无法与192.168.28.111谈判:没有找到匹配的密码。他们的报价:3des 128-cbc,3 3des cbc,河豚-cbc preauth
在CopSSH上。
Java代码块
public void sshExecPassword(String host, String USERNAME, String PASSWORD, String command) {
App objApp = new App();
int port = 22;
try {
/**
* Create a new Jsch object This object will execute shell commands
* or scripts on server
*/
JSch jsch = new JSch();
/*
* Open a new session, with your username, host and port Set the
* password and call connect. session.connect() opens a new
* connection to remote SSH server. Once the connection is
* established, you can initiate a new channel. this channel is
* needed to connect to remotely execution program
*/
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
Session session = jsch.getSession(USERNAME, host, port);
session.setConfig(config);
session.setPassword(PASSWORD);
session.connect();
// create the excution channel over the session
ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
// Gets an InputStream for this channel. All data arriving in as
// messages from the remote side can be read from this stream.
InputStream in = channelExec.getInputStream();
// Set the command that you want to execute
// In our case its the remote shell script
String str = command;
channelExec.setCommand(str);
channelExec.connect();
// Read the output from the input stream we set above
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line;
while ((line = reader.readLine()) != null) {
System.out.println(line);
}
// retrieve the exit status of the remote command corresponding to
// this channel
int exitStatus = channelExec.getExitStatus();
// Safely disconnect channel and disconnect session. If not done
// then it may cause resource leak
channelExec.disconnect();
session.disconnect();
if (exitStatus < 0) {
System.out.println("Done, but exit status not set! " + exitStatus);
objApp.writeLogs("120","Done, but exit status not set! ");
} else if (exitStatus > 0) {
System.out.println("Done, but with error!");
objApp.writeLogs("120","Done, but with error!");
} else {
System.out.println("Done!");
objApp.writeLogs("121","SSH connection successful");
}
} catch (Exception e) {
System.err.println("Error: " + e);
final StringWriter sw = new StringWriter();
final PrintWriter pw = new PrintWriter(sw, true);
e.printStackTrace(pw);
objApp.writeLogs("120", sw.getBuffer().toString());
}
}和以下版本的CopSSH主机
OpenSSH_7.1p2,OpenSSL 1.0.2e 2015年12月3日
有人能提出解决办法吗?
发布于 2016-12-29 21:34:02
这是因为在OpenSSH的最新版本中缺乏对遗留密码的支持。检查这个Copssh常见问题以获得解决方案。背景信息也可以找到这里。
发布于 2017-01-02 05:14:22
最新的jcraft jar修复了这个问题
https://stackoverflow.com/questions/41376900
复制相似问题