【问题标题】:How to access apache mina ssh server from remote machine?如何从远程机器访问 apache mina ssh 服务器?
【发布时间】:2019-03-18 08:12:23
【问题描述】:

我创建了一个 Amazon Linux 2 实例,并在其中部署了一个使用 systemd 启动的 Java 程序。 Java 程序是一个 vertx-shell 应用程序,它使用 Apache Mina 在端口 2000 上启动 SSH 服务器。应该可以通过 2 种方式连接到 SSH 服务器:公钥或密码验证。

在端口 22 上进行经典 ssh 身份验证以访问我的亚马逊实例后,我可以使用密码 auth 连接到本地端口 2000 上运行的 java ssh 服务器。但是,当我尝试从提供 Amazon 私钥的本地计算机连接到 SSH 服务器时,连接卡在“debug1: Local version string SSH-2.0-OpenSSH_7.5”行并最终被拒绝超时 2 分钟后:

ssh -i /Users/toto/.ssh/my_amazon_key.pem -p 2000 ec2-user@my-application.server.com -vvv
OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /Users/toto/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug2: resolving "my-application.server.com" port 2000
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to my-application.server.com [35.XXX.XX.XX] port 2000.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/toto/.ssh/my_amazon_key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/toto/.ssh/my_amazon_key.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
ssh_exchange_identification: Connection closed by remote host

在 Java 应用程序日志中,我可以看到有人尝试连接到 SSH 服务器,但 2 分钟后验证失败。

当然,我已经在我的亚马逊安全组中检查了我已经打开了 2000 端口。在我的情况下,没有拒绝 IP。

这是运行 SSH 服务器的 Java 代码:

ShellService service = ShellService.create(vertx,
                new ShellServiceOptions()
                        .setTelnetOptions(
                            new TelnetTermOptions().
                                setHost("localhost").
                                setPort(5000))
                        .setSSHOptions(
                            new SSHTermOptions().
                                setHost("0.0.0.0").
                                setPort(2000).
                                setKeyPairOptions(new JksOptions().
                                        setPath("ssh/keystore.jks").
                                        setPassword("wibble")).
                                setAuthOptions(new ShiroAuthOptions().
                                        setConfig(new JsonObject().put("properties_path", "classpath:ssh/auth.properties"))))
        );

有什么想法吗? Vertx/Apache Mina 配置?在 22 端口和 2000 端口上运行的 SSHD 冲突?

【问题讨论】:

    标签: java ssh vert.x apache-mina amazon-linux


    【解决方案1】:

    好的,我终于找到了问题所在。实际上,我必须做两件事:

    1. 我把端口从2000改成了3000,然后就没有卡住了,至少我能用密码认证了。但是公钥认证仍然失败。所以我想其他东西已经在初始端口 2000 上运行,导致连接卡住。
    2. 我正在使用特定用户 vertx 启动我的 java 应用程序,因此 Apache Mina SSH 服务器正在为用户 vertx 寻找一个不存在的 authorized_keys 文件。一旦我使用 vertx 用户主目录中自己的 .ssh 目录中的公钥创建了它,并具有正确的权限,那么我就可以提供相应的私钥进行身份验证。

    【讨论】:

      猜你喜欢
      • 2015-06-22
      • 1970-01-01
      • 2017-06-16
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多