【问题标题】:Apache mina sshd client: jump server with password authenticationApache mina sshd 客户端:使用密码认证跳转服务器
【发布时间】:2023-02-02 17:48:33
【问题描述】:

我正在尝试实现一个基于 MINA sshd 的 ssh 客户端,通过 ssh 跳转与终端服务器通信。

根据文档 (https://github.com/apache/mina-sshd/blob/master/docs/internals.md#ssh-jumps) 和在 Internet 上找到的其他信息,我的代码看起来像这样。

    SshClient client = SshClient.setUpDefaultClient();
    client.setHostConfigEntryResolver(
        HostConfigEntry.toHostConfigEntryResolver(
            Arrays.asList(
                new HostConfigEntry("server", "end-server", 22, "user1", "proxy"),
                new HostConfigEntry("proxy", "proxy-server", 22, "user2"))));

    client.start();

    try (ClientSession session = client.connect("server").verify(defaultTimeout).getSession()) {

      session.addPasswordIdentity("password1"); // password for the end-server
      session.auth().verify(defaultTimeout);
      try (ByteArrayOutputStream responseStream = new ByteArrayOutputStream();
          ByteArrayOutputStream errorStream = new ByteArrayOutputStream();
          ClientChannel channel = session.createExecChannel("pwd"))
      {
        channel.setOut(responseStream);
        channel.setErr(errorStream);
        try {
          channel.open().verify(defaultTimeout);
          try (OutputStream pipedIn = channel.getInvertedIn()) {
            pipedIn.write("dir".getBytes());
            pipedIn.flush();
          }
          channel.waitFor(EnumSet.of(ClientChannelEvent.CLOSED), defaultTimeout);
          String error = errorStream.toString();
          if (!error.isEmpty()) {
            throw new Exception(error);
          }
          System.out.println(responseStream);
        } finally {
          channel.close(false);
        }
      }
    }

如果对代理的身份验证是通过密钥身份验证并且终端服务器使用密码身份验证,则此实现工作正常。

问题是,实际上我使用的跳转服务器仅提供密码身份验证,而我找不到提供其凭据的方法。

如何提供跳转服务器凭据?

谢谢!

【问题讨论】:

    标签: java apache-mina apache-sshd


    【解决方案1】:

    我遇到了和你一样的问题。你解决了吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 2018-11-08
      • 2012-11-03
      • 1970-01-01
      • 1970-01-01
      • 2016-04-11
      相关资源
      最近更新 更多