net.schmizz.sshj.userauth.UserAuthException:已用尽的可用身份验证方法

问题描述 投票:6回答:1

第一次询问stackoverflow,也使用sshj。除了sshj提供的示例之外,我还没有真正找到任何好的资源来帮助使用此API。

我一直在尝试使用sshj进行远程端口转发,并且遇到了此错误。

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

我使用VM测试了身份验证,但未使用公共密钥。我将使用它来连接到我知道其登录名的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();
    }
}

可能不是最好的(甚至是正确的)方法。

ssh portforwarding sshj
1个回答
0
投票

我写了一个类似的先前问题的示例,您可以在可连接到EC2实例的groovyconsole中直接运行:https://stackoverflow.com/a/15800383/311525

© www.soinside.com 2019 - 2024. All rights reserved.