ssh - net.schmizz.sshj.userauth.UserAuthException : Exhausted available authentication methods

标签 ssh portforwarding sshj

第一次询问 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();
    }
}

可能不是最好的(甚至是正确的)方式来做到这一点。

最佳答案

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

关于ssh - net.schmizz.sshj.userauth.UserAuthException : Exhausted available authentication methods,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15805242/

上一篇:php - SQL 清理和 PHP

下一篇:PHP 组合数组

相关文章:

windows - Parallels - 在 OSx 主机中访问 Visual Studio 2012 Express 服务器

python - 如何使用python将端口转发到路由器

java - 使用 SSHJ 和 ed25519 进行 SFTP 上传遇到关键问题

java - 使用 SSHj 进行 SSH 端口转发

docker - 如何将 SSH 私钥挂载到 Docker for Windows 容器?

python - "ROS"如何通过SSH远程控制Python脚本

Git 失败并显示 "fatal: protocol error: bad line length character: Pass"

bash - 如何将ssh作业发送到后台

docker - Boot2Docker - 以本地主机身份访问网络服务器

java - 使用 sshj java 库在我的 Amazon EC2 机器上执行 "sudo"命令