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

Folders and files

NameName
Last commit message
Last commit date

Latest commit

8b996b3 · Apr 23, 2025
Jul 5, 2024
Apr 23, 2025
Dec 29, 2024
Nov 29, 2020
Mar 4, 2017
Oct 10, 2016
Jul 6, 2023
Apr 23, 2025
Apr 23, 2025
Apr 23, 2025
Apr 23, 2025
Jul 12, 2024
May 7, 2021
Apr 10, 2021
Feb 26, 2019

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