javaauthenticationsshsshj

SSHJ is not able to connect remote Linux server throws UserAuthException: Exhausted available authentication methods


I am trying to run the following Java code using sshj :-

public static void main(String[] args) throws IOException {

    SSHClient ssh = new SSHClient();
    ssh.loadKnownHosts();
    ssh.connect("host", port);
    try {
        ssh.authPassword("user", "passwd");
        ssh.useCompression();

        final String src = System.getProperty("user.home") + File.separator + "test_file";
        ssh.newSCPFileTransfer().upload(new FileSystemFile(src), "/tmp/");
    } finally {
        ssh.disconnect();
        ssh.close();
    }
}

But it is throwing exception -

Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods
    at net.schmizz.sshj.SSHClient.auth(SSHClient.java:231)
    at net.schmizz.sshj.SSHClient.auth(SSHClient.java:206)
    at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:292)
    at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:262)
    at net.schmizz.sshj.SSHClient.authPassword(SSHClient.java:246)
    at sample.SCPUpload.main(SCPUpload.java:17)

I can connect the host using same credentials via Putty. I am using JDK "1.8.0_151". What is wrong here?


Solution

  • Typically it means that either your password is wrong, or you're not allowed to connect using the 'password' authentication method.