开发者

Authentication with Private Key does not work

开发者 https://www.devze.com 2022-12-07 18:22 出处:网络
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

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消