Problems with jsch session.connect ()

I am new to Jsch and I am trying to connect to a third party via sftp. I can connect via ssh, so I know that I have the correct user, host, port and private key file, but when I try to connect via Jsch, I get an "Auth failed" error message that is almost, but not quite useful . Here is my code that I compiled from examples on the Internet:

String pvtkey = "{unixpath}/id_dsa";
ChannelSftp sftp = null;
JSch jsch = new JSch();
Session session = null;



    try{
        jsch.setKnownHosts("{unixpath}/known_hosts");
        jsch.addIdentity(pvtkey);
        session = jsch.getSession(user, connectionURL, 22);
        Properties config = new Properties();
        config.put("StrictHostKeyChecking", "no");
        session.setConfig(config);
        session.connect();
                    ...some other code that never gets called
             }catch(JSchException e){
                log.info(e.getMessage());
                log.error(e.getCause());
             }

, , session.connect(). URL , . pvtkey known_hosts - unix , , , script tht, . sftp, , Jsch-? ?

+3
3

, , JSch ( .pub) , addIdentity(). , , .

, SSH , - ( , ). ( ) , JSch , .

0

config.put("StrictHostKeyChecking", "no");

. . , . .

0

  use the code below for me: try { Properties config = new Properties(); config.put("StrictHostKeyChecking", "no"); config.put("PreferredAuthentications", "publickey,keyboard-interactive,password"); jsch.addIdentity(); System.out.println("identity added "); session = jsch.getSession(user, host, 22); // session.setPassword("123"); session.setConfig(config); session.connect(); Channel channel = session.openChannel("sftp"); channel.connect(); } catch (JSchException e) { e.printStackTrace();
} catch (SftpException e) { e.printStackTrace(); }

0
source

All Articles