如何从远程机器访问 apache mina ssh 服务器?

How to access apache mina ssh server from remote machine?

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

在端口 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。

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

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 米娜配置?端口 22 和端口 2000 上的 SSHD 运行 之间存在冲突?

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

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