Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"com.jcraft.jsch.JSchException: Auth fail" with working passwords

Tags:

java

jsch

While trying to upload the file to our server, i am getting the following exception

    com.jcraft.jsch.JSchException: Auth fail
        at com.jcraft.jsch.Session.connect(Session.java:464)
        at com.jcraft.jsch.Session.connect(Session.java:158)
        at FtpService.transferFileToReciever(FtpService.java:80)
        at FtpService.transferFileToReciever(FtpService.java:54)
        at FtpService.transferFileToRecievers(FtpService.java:44)
        at FtpService.transferSingeFile(FtpService.java:241)
        at FtpService.main(FtpService.java:26)
    Auth fail

The part of function transferFileToReciever from source file is

        JSch jsch = new JSch();
        jsch.addIdentity("/root/.ssh/id_dsa");
        Session session = jsch.getSession(username, host, 22);

        session.setUserInfo(serverinfo);
        session.connect(); //geting exception here

        boolean ptimestamp = true;

The passwords are working, since i can do login using ssh, but using JSCh it doesnt work even provided with key, username and password. Using id_dsa key with java version "1.6.0_25". What could be the error?

Found other similar question, but not the answer. Thanks in advance.

like image 730
vinay Avatar asked Jun 17 '13 13:06

vinay


4 Answers

Tracing the root cause, i finally found that the public key of type dsa is not added to the authorized keys on remote server. Appending the same worked for me.

The ssh was working with rsa key, causing me to look back in my code.

thanks everyone.

like image 57
vinay Avatar answered Oct 13 '22 18:10

vinay


Try to add auth method explicitly as below, because sometimes it is required:

session.setConfig("PreferredAuthentications", "password");
like image 20
Amit Pawar Avatar answered Oct 13 '22 20:10

Amit Pawar


I have also face the Auth Fail issue, the problem with my code is that I have

channelSftp.cd("");

It changed it to

channelSftp.cd(".");

Then it works.

like image 4
Harry Avatar answered Oct 13 '22 19:10

Harry


If username/password contains any special characters then inside the camel configuration use RAW for Configuring the values like

  • RAW(se+re?t&23) where se+re?t&23 is actual password

  • RAW({abc.ftp.password}) where {abc.ftp.password} values comes from a spring property file.

By using RAW, solved my issue.

http://camel.apache.org/how-do-i-configure-endpoints.html

like image 4
Deepak Singla Avatar answered Oct 13 '22 20:10

Deepak Singla