我正在尝试使用JSch进行SFTP,但是我遇到了一些错误:
com.jcraft.jsch.JSchException:密码'aes256-cbc'是必需的,但它不可用.
以下是我使用的代码.我错过了什么吗?
JSch jsch = new JSch();
Session session = null;
jsch.addIdentity("C:\\privatekey.ppk", "Password");
session = jsch.getSession("user", "54.251.240.234", 22);
session.setConfig("StrictHostKeyChecking", "no");
Channel channel = session.openChannel("sftp");
channel.connect();
ChannelSftp sftpChannel = (ChannelSftp) channel;
sftpChannel.put("C:\\Users\\test.txt", "/home/user/test.txt");
sftpChannel.exit();
session.disconnect();
Run Code Online (Sandbox Code Playgroud)
堆栈跟踪
[8/30/13 1:56:26:556 SGT] 00000021 SystemErr R com.jcraft.jsch.JSchException: The cipher 'aes256-cbc' is required, but it is not available.
[8/30/13 1:56:26:557 SGT] 00000021 SystemErr R at com.jcraft.jsch.KeyPair.loadPPK(KeyPair.java:1017)
[8/30/13 1:56:26:557 SGT] 00000021 SystemErr R at com.jcraft.jsch.KeyPair.load(KeyPair.java:590)
[8/30/13 1:56:26:557 SGT] 00000021 SystemErr R at com.jcraft.jsch.KeyPair.load(KeyPair.java:542)
[8/30/13 1:56:26:557 SGT] …Run Code Online (Sandbox Code Playgroud) 我一直在与JSch合作开发一个项目,该项目连接到Unix服务器。使用ecdsa-sha2-nistp256进行密钥交换连接到服务器时遇到问题。
奇怪的是,我已经从这篇文章中启用了JCE(使用JDK 1.8 65),但是仍然没有骰子。
如果我正确阅读日志,则表明客户端确实启用了ecdsa-sha2-nistp256。但是它回落到ssh-rsa。也许我错过了一步?
错误:
UnknownHostKey: *********. RSA key fingerprint is 1d:ac:f7:50:10:07:51:4b:17:9c:cd:b5:be:25:75:28
Run Code Online (Sandbox Code Playgroud)
这是日志:
INFO: Connecting to ******* port 22
INFO: Connection established
INFO: Remote version string: SSH-2.0-OpenSSH_6.6.1
INFO: Local version string: SSH-2.0-JSCH-0.1.53
INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256
INFO: CheckKexes: diffie-hellman-group14-sha1,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521
INFO: CheckSignatures: ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521
INFO: SSH_MSG_KEXINIT sent
INFO: SSH_MSG_KEXINIT received
INFO: kex: server: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
INFO: kex: server: ssh-rsa,ecdsa-sha2-nistp256,ssh-ed25519
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
INFO: kex: server: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-gcm@openssh.com,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
INFO: kex: server: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
INFO: kex: server: hmac-md5-etm@openssh.com,hmac-sha1-etm@openssh.com,umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac-sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-ripemd160-etm@openssh.com,hmac-sha1-96-etm@openssh.com,hmac-md5-96-etm@openssh.com,hmac-md5,hmac-sha1,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
INFO: kex: server: none,zlib@openssh.com
INFO: kex: …Run Code Online (Sandbox Code Playgroud) 有关此异常的问题有两个:
我正在使用Windows机器并尝试连接到使用运行Ubuntu的Vagrant创建的VM.这是我的代码:
public static void main(String[] args) {
String host = "localhost";
String username = "vagrant";
int port = 2200;
String privateKey = "C:\\keys\\openSSH_pair1\\open_ssh_private";
JSch js = new JSch();
try {
js.addIdentity(privateKey, "pass");
js.setKnownHosts("C:\\Users\\user\\.ssh\\known_hosts");
Session session = js.getSession(username, host, port);
session.connect();
System.out.println("Connected");
} catch (JSchException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
@Pascal建议设置strictHostKeyChecking为no,对我有用,但这不是首选的解决方案.他首选的解决方案是从命令行进行SSH,以便将主机添加到known_hosts文件中.我已经安装并执行了Git ssh -i openSSH_pair1\open_ssh_private vagrant@localhost -p 2200
并收到此输出,然后被提示输入密码并建立连接
无法建立主机'[localhost]:2200([127.0.0.1]:2200)'的真实性.ECDSA密钥指纹是11:5d:55:29:8a:77:d8:08:b4:00:9b:a3:61:93:fe:e5.您确定要继续连接(是/否)吗?是警告:永久性地将'[localhost]:2200'(ECDSA)添加到已知主机列表中.
所以现在我的known_hosts文件git_home\.ssh包含一个条目localhost:2200,我也把known_hosts文件放入user_home\.ssh.我还把我的私钥放在VM上我试图ssh并运行它来生成一个公钥并将其添加到authorized_keys …
我正在尝试从客户端计算机连接 sftp 服务器。但是 com.jcraft.jsch.JSchException:算法协商失败了我遇到的这种错误。
com.jcraft.jsch.JSchException: Algorithm negotiation fail
at com.jcraft.jsch.Session.receive_kexinit(Session.java:540)
at com.jcraft.jsch.Session.connect(Session.java:288)
at com.jcraft.jsch.Session.connect(Session.java:145)
at com.na.common.NewReading.main(NewReading.java:28)
Run Code Online (Sandbox Code Playgroud)
我试图通过在 Jenkins 中使用算法协商失败 SSH来解决这个问题,并且我已经更改了 sshd_config 中的 KexAlgorithms,但出现错误。
所以请帮助我。谢谢