0

Somebody asked for this and there is a pull-request which contains code that somehow was rewritten before it got merged and somebody managed to code a solution based on the pull-request. However, there is no example for the final version in that library.

Therefore, that doesn't really help me with my limited understanding of ssh and all. Basically there are two scenarios I want to solve:

  1. common SSH-session via some jump-hosts:

    • user1@jump1.com
    • user2@jump2.com
    • user3@jump3.com
    • admin@server.com

    ending in an ssh-session where the connecting user is free to work around in that ssh-shell at server.com, i.e. what a normal ssh admin@server.com-command would do in the shell on jump3.com.

  2. like the above but ending in a port forwarding to server.com:80

That is possible with ssh's ProxyCommand, but I want to code this with SSHJ. And that's where I fail to figure out how to do this.

What I have now is

SSHClient hop1 = new SSHClient();
try {
  Path knownHosts = rootConfig.getKnownHosts();
  if (knownHosts != null) {
    hop1.loadKnownHosts(knownHosts.toFile());
  } else {
    hop1.loadKnownHosts();
  }

  Path authenticationFile = hop1Config.getAuthenticationFile();
  if (authenticationFile != null) {
    KeyProvider keyProvider = hop1.loadKeys(authenticationFile.toString(), (String) null);
    hop1.authPublickey(hop1Config.getUser(), keyProvider);
  } else {
    hop1.authPassword(hop1Config.getUser(), hop1Config.getPassword());
  }

  // I found these methods:
  hop1.getConnection();
  hop1.getSocket();

  // and now what?
} catch (IOException e) {
  logger.error("Failed to open ssh-connection to {}", hop1Config, e);
}

I noticed class LocalPortForwarder.DirectTCPIPChannel, but I don't know with what values I should instantiate it or how to use it with the rest afterwards.

sjngm
  • 12,423
  • 14
  • 84
  • 114
  • To the downvoter: it would have been nice to know what's missing for you and I'd have added that info. As far as I'm concerned it's all here. – sjngm May 06 '19 at 15:49
  • I'm still working on the PR, but got side-tracked with one of my other projects... There is support for ssh jumpstations already, the PR is for a special case where the user does not want to open a local port for the forward. For regular SSH jumpstations you can use LocalPortForwarder, which implements `ssh -L::` semantics – Hiery Nomus May 07 '19 at 11:54
  • @HieryNomus That's good to hear. But, how do I do this nested across a few jump stations? Please let me know when you have finished your PR. – sjngm May 07 '19 at 16:04
  • Just merged it to master... Look at the Jump example. – Hiery Nomus May 08 '19 at 12:12
  • @HieryNomus Thanks, but I don't see a new version of the library. It looks as if 0.27.0 still is the latest version. So I don't see the method `SSHClient.newDirectConnection()`. – sjngm May 10 '19 at 15:39
  • 1
    @HieryNomus ... still waiting ... – sjngm Sep 14 '19 at 21:34
  • 1
    @HieryNomus ... still waiting ... – sjngm Dec 06 '19 at 21:04
  • 1
    ... still waiting ... :) – Devin R Mar 03 '20 at 16:56

0 Answers0