Skip to content

Latest commit

 

History

History
58 lines (45 loc) · 1.68 KB

README.md

File metadata and controls

58 lines (45 loc) · 1.68 KB

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