A pure Java implementation to tunnel two TCP endpoints through SSH. It is an
abstraction above JSch that is able to understand more sophisticated
OpenSSH configurations (i.e. the ProxyJump
and ProxyCommand
options) which
involve multiple hops to reach a target host.
Add the following Maven dependency to your project:
<dependency>
<groupId>de.cronn</groupId>
<artifactId>ssh-proxy</artifactId>
<version>1.3</version>
</dependency>
# cat ~/.ssh/config
Host jumpHost1
User my-user
HostName jumphost1.my.domain
Host jumpHost2
User other-user
ProxyJump jumpHost1
Host targetHost
ProxyCommand ssh -q -W %h:%p jumpHost2
try (SshProxy sshProxy = new SshProxy()) {
int targetPort = 1234;
int port = sshProxy.connect("jumpHost2", "targetHost", targetPort);
try (Socket s = new Socket(SshProxy.LOCALHOST, port)) {
OutputStream out = s.getOutputStream();
InputStream in = s.getInputStream();
// ...
}
}
- Java 8+
- JSch (with JZlib)