Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

JSch: Auth cancelled.

Se Hee Lee
2010-03-26
2013-05-28
  • Se Hee Lee
    Se Hee Lee
    2010-03-26

    Hello.

    I am trying out the latest jsch with public key auth. For some reason, I get the Auth Cancelled exception with the code below.

    I am on Windows and I have created the openssh2 private key from putty (keygen). I am using that here.

    Also, I already added my public to the authorized_keys on the remote host. I also verified that I can ssh there with putty without being prompted for the password.

    In any rate, here is the code snippet.

    String realScpUser = scpUser;
            String realScpTo = scpTo;
            String realScpOptions = scpOptions;

            if (props != null && !props.isEmpty()) {
                realScpUser = props.containsKey(USER) ? props.getProperty(USER) : scpUser;
                realScpTo = props.containsKey(USER) ? props.getProperty(TO) : scpTo;
                realScpOptions = props.containsKey(USER) ? props.getProperty(OPTIONS) : scpOptions;
            }

            JSch jsch = new JSch();
            try {
                jsch.addIdentity("c:\\users\\sleeddat\\Documents\\id_rsa.pem");
            }
            catch (JSchException e) {
                throw new MessageNotSentException("Error", e);
            }

            try {
                Session session = jsch.getSession(realScpUser, realScpTo, 22);
                session.setConfig("StrictHostKeyChecking", "no");
    //            session.setConfig("server_host_key", "ssh-rsa");
               
    //            session.setUserInfo(new UserInfo() {
    //                public String getPassphrase() {
    //                    return null;
    //                }
    //
    //                public String getPassword() {
    //                    return null;
    //                }
    //
    //                public boolean promptPassphrase(String arg0) {
    //                    return false;
    //                }
    //
    //                public boolean promptPassword(String arg0) {
    //                    return true;
    //                }
    //
    //                public boolean promptYesNo(String arg0) {
    //                    return false;
    //                }
    //
    //                public void showMessage(String arg0) {
    //                }
    //            });
                session.connect();
            }
            catch (JSchException e) {
                throw new MessageNotSentException("Error", e);
            }

     
  • Se Hee Lee
    Se Hee Lee
    2010-03-26

    BTW,

    I am getting this error.

    Caused by: com.jcraft.jsch.JSchException: Auth cancel
    at com.jcraft.jsch.Session.connect(Session.java:451)
    at com.jcraft.jsch.Session.connect(Session.java:150)
    at mo.etl.SCPMessageSender2.sendMessage(SCPMessageSender2.java:114)
    … 19 more