[JSch-users] Connection with private key
Status: Alpha
Brought to you by:
ymnk
From: Luca D. <lu...@de...> - 2010-05-24 15:18:27
|
Good afteroon, I'm working on a java project and I'm going to use JSch for SFTP connection. My test class worked fine when I used user/pass authentication, while it ends with "*Auth fail*" when I try to switch to user/key authentication. If I manually connect to the server using OpenSSH client it works, so SSH server should work and accept the key. I set up a simple logger, from its output it seems JSch skips publickey method... without errors. Where am I wrong? Thanks! My code: --- public class JSchTest { public JSchTest() { JSch jsch = new JSch(); JSch.setLogger(new MyLogger()); try { jsch.addIdentity("C:\\id_dsa"); } catch (JSchException e) { e.printStackTrace(); System.exit(1); } Session session = null; try { session = jsch.getSession("myuser", "myhost"); } catch (JSchException e) { e.printStackTrace(); System.exit(1); } Properties properties = new Properties(); properties.put("StrictHostKeyChecking", "no"); session.setConfig(properties); try { session.connect(); System.out.println("Connected!"); } catch (JSchException e) { e.printStackTrace(); System.exit(1); } System.exit(0); } --- MyLogger output: --- INFO: Connecting to myhost port 22 INFO: Connection established INFO: Remote version string: SSH-2.0-OpenSSH_4.3 INFO: Local version string: SSH-2.0-JSCH-0.1.42 INFO: CheckCiphers: aes256-ctr,aes192-ctr,aes128-ctr,aes256-cbc,aes192-cbc,aes128-cbc,3des-ctr,arcfour,arcfour128,arcfour256 INFO: aes256-ctr is not available. INFO: aes192-ctr is not available. INFO: aes256-cbc is not available. INFO: aes192-cbc is not available. INFO: arcfour256 is not available. INFO: SSH_MSG_KEXINIT sent INFO: SSH_MSG_KEXINIT received INFO: kex: server->client aes128-ctr hmac-md5 none INFO: kex: client->server aes128-ctr hmac-md5 none INFO: SSH_MSG_KEXDH_INIT sent INFO: expecting SSH_MSG_KEXDH_REPLY INFO: ssh_rsa_verify: signature true WARN: Permanently added 'myhost' (RSA) to the list of known hosts. INFO: SSH_MSG_NEWKEYS sent INFO: SSH_MSG_NEWKEYS received INFO: SSH_MSG_SERVICE_REQUEST sent INFO: SSH_MSG_SERVICE_ACCEPT received INFO: Authentications that can continue: gssapi-with-mic,publickey,keyboard-interactive,password INFO: Next authentication method: gssapi-with-mic INFO: Authentications that can continue: publickey,keyboard-interactive,password INFO: Next authentication method: publickey INFO: Authentications that can continue: password INFO: Next authentication method: password INFO: Disconnecting from devnagios port 22 com.jcraft.jsch.JSchException: Auth fail at com.jcraft.jsch.Session.connect(Session.java:452) at com.jcraft.jsch.Session.connect(Session.java:150) at JSchTest.<init>(JSchTest.java:38) at JSchTest.main(JSchTest.java:51) --- |