0

I try to connect SFTP Server using Jsch Library. It works when i use username/password, but with private/public key does not work. i have been read all questions about this theme in Stackoverflow and in other Site webs, but i did not find what i search for.

To test my private key, i have used Terminal(also WinSCP), it works fine, but with Java Code i get this " Auth fail"

This is an Example:

 public static void main(String[] args) throws JSchException, SftpException, IOException {
        JSch jsch = new JSch();
        Properties config=new Properties();
        config.put("StrictHostKeyChecking", "no");
        jsch.addIdentity("path_to_private_key");
        Session session;
        session = jsch.getSession("user", "host", 22);

        session.setConfig(config);
//        session.setPassword("pass");
        session.connect();
        System.out.println("CONNECT !!! ");
        session.disconnect();
    }

. I have generated keys using this command: ssh-keygen -C "" -m PEM id_rsa . past public key in /.ssh/authorized_keys

Any help please?

Amine
  • 1
  • Start here: [Public key authentication fails with JSch but work with OpenSSH with the same key](https://stackoverflow.com/q/72743823/850848). – Martin Prikryl Dec 07 '22 at 07:51

0 Answers0