Skip to content

Pure Java implementation for SSH port tunneling that understands ProxyJump and ProxyCommand

License

Notifications You must be signed in to change notification settings

cronn/ssh-proxy

Repository files navigation

CI Maven Central Apache 2.0 codecov Valid Gradle Wrapper

SSH Proxy

A pure Java implementation for SSH port tunneling that is able to understand OpenSSH configurations which involve multiple hops to reach a target host. This library essentially combines JSch with the ability to understand ProxyJump or ProxyCommand configurations in your local ~/.ssh/config file.

See our blog post "Tunneling Basics – Part II: OpenSSH Configuration Files" for some context where and how this library can be used.

Usage

Add the following Maven dependency to your project:

<dependency>
    <groupId>de.cronn</groupId>
    <artifactId>ssh-proxy</artifactId>
    <version>1.6</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 randomLocalPort = sshProxy.connect("jumpHost2", "targetHost", targetPort);
    try (Socket s = new Socket(SshProxy.LOCALHOST, randomLocalPort)) {
        OutputStream out = s.getOutputStream();
        InputStream in = s.getInputStream();
        // ...
    }
}

Dependencies

About

Pure Java implementation for SSH port tunneling that understands ProxyJump and ProxyCommand

Topics

Resources

License

Stars

Watchers

Forks

Contributors 4

  •  
  •  
  •  
  •