net.schmizz.sshj.userauth.UserAuthException: исчерпаны доступные методы аутентификации

Первый раз спрашивая о stackru, а также используя sshj. Помимо примеров, предоставленных с sshj, я не нашел хороших ресурсов, которые могли бы помочь в использовании этого API.

Я пытался сделать удаленную переадресацию портов с помощью sshj и столкнулся с этой ошибкой.

Exception in thread "main" net.schmizz.sshj.userauth.UserAuthException: Exhausted available authentication methods

Я проверил аутентификацию с виртуальной машиной, но без использования открытого ключа. Я буду использовать это для подключения к экземпляру EC2, на котором я знаю логин.

public void startRemotePortForwardingConnection(LocalPortForwarder.Parameters parameters) throws IOException{
    sshClient.connect(parameters.getLocalHost());
    this.connectionStatus = CONNECTED;
    System.out.print("Connected to localhost" + NEWLINE);

    try {
        sshClient.authPassword(this.username, this.password);
        System.out.print("Authorized with as user " + username + " with password " + password + NEWLINE);

        // the local port we should be listening on
        RemotePortForwarder.Forward localPortToListenOn = new RemotePortForwarder.Forward(parameters.getLocalPort());
        System.out.print("localPortToListenOn initialized" + NEWLINE);

        // where we should forward the packets
        InetSocketAddress socketAddress = new InetSocketAddress(parameters.getRemoteHost(), parameters.getRemotePort());
        SocketForwardingConnectListener remotePortToForwardTo = new SocketForwardingConnectListener(socketAddress);
        System.out.print("remotePortToForwardTo initialized" + NEWLINE);

        //bind the forwarder to the correct ports
        sshClient.getRemotePortForwarder().bind(localPortToListenOn, remotePortToForwardTo);
        System.out.print("ports bound together" + NEWLINE);

        sshClient.getTransport().setHeartbeatInterval(30);
        sshClient.getTransport().join();
    }
    finally {
        sshClient.disconnect();
    }
}

Вероятно, не самый лучший (или даже правильный) способ сделать это.

2 ответа

Я написал пример для аналогичного предыдущего вопроса, который вы можете запустить непосредственно в groovyconsole, который будет подключаться к экземпляру EC2: /questions/35431750/sshj-vhod-s-parnoj-paryi-v-ekzemplyar-ec2/35431765#35431765

Попробуй использовать client.addHostKeyVerifier(new PromiscuousVerifier());. Я отправляю две конфигурации, первую с открытым ключом, вторую с именем пользователя/паролем.

      private static SSHClient setupSshj(String remoteHost, String username, String password) throws Exception {
    SSHClient client = new SSHClient();
    client.addHostKeyVerifier(new PromiscuousVerifier());
    client.connect(remoteHost);
    client.authPassword(username, password);
    return client;
}

private static SSHClient setupSshWithPublicKey(String remoteHost, int port, String username, String publicKey) throws Exception {
    SSHClient client = new SSHClient();
    client.addHostKeyVerifier(new PromiscuousVerifier());
    client.connect(remoteHost, port);
    client.authPublickey(username, publicKey);
    return client;
}
Другие вопросы по тегам