Skip to content

Pure Java implementation to tunnel to TCP endpoints through SSH

License

Notifications You must be signed in to change notification settings

ralfbergs/ssh-proxy

 
 

Repository files navigation

Build Status Maven Central Apache 2.0 Coverage Status

SSH Proxy

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.

Usage

Add the following Maven dependency to your project:

<dependency>
    <groupId>de.cronn</groupId>
    <artifactId>ssh-proxy</artifactId>
    <version>1.3</version>
</dependency>

Example

# 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();
        // ...
    }
}

Dependencies

About

Pure Java implementation to tunnel to TCP endpoints through SSH

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 99.7%
  • Shell 0.3%