Documentation
Open Source Release Policy
Export Compliance
Using BouncyCastle
Installing the API
Enabling Logging
Per-Connection Logging
Third Party Dependencies
Generating SSH Keys
Using BouncyCastle
Using SSH Public Keys in Java
Supporting ED25519/Curve25519
Supporting Compression
Integrating Licensing into Maven Builds
Creating an SSH Client
Public Key Authentication
Keyboard Interactive Authentication
Public Key Authentication with sshagent
Executing Single Commands
Executing Commands within a Shell
Transferring Files
Connecting through Proxies
Display the Authentication Banner
Using the SFTP Client
Port Forwarding
Working Examples
Configuring Listening Interfaces
Configuring Host Keys
Password Authentication
Public Key Authentication
Challenge-Response Authentication
Configuring Port Forwarding
Configuring SFTP
Supporting SCP
Implementing your own File System
Creating an Interactive Terminal
Proxy Protocol Support
Port Forwarding
One of the major performance improvements in the Maverick Synergy API has been in the performance of tunnels over the SSH connection. This has benefitted from the move to NIO from standard sockets and threaded/blocking I/O.
By default, the API will not allow port forwarding. You have to enable this on your SshClient before you use the forwarding API.
ssh.getForwardingPolicy().allowForwarding();
Code language: CSS (css)
This will allow forwarding only from the localhost interface. If you want to allow external hosts to access sockets listening for forwarding connections, you also need to enable gateway forwarding.
ssh.getForwardingPolicy().allowGatewayForwarding();
Code language: CSS (css)
Local Forwarding
You can start a local forwarding with the startLocalForwarding method. For example, the following code creates a local listener on port 8080 and forwards this to port 80 on the remote host.
ssh.startLocalForwarding("127.0.0.1", 8080, "127.0.0.1", 80);
Code language: CSS (css)
If you want to start the local listener on a random port, pass zero as the local port number and consult the integer value returned for the random port.
int randomPort = ssh.startLocalForwarding("127.0.0.1", 0, "127.0.0.1", 80);
Code language: JavaScript (javascript)
To stop the local forwarding at any time during the lifetime of the connection use:
ssh.stopLocalForwarding("127.0.0.1", 8080);
Code language: CSS (css)
When starting with a random port, pass the randomly chosen port back to the stop method.
You can also stop all local forwarding with:
ssh.stopLocalForwarding();
Code language: CSS (css)
Remote Forwarding
Remote forwarding allows connections from the remote network back to your local machine or other services in the local network.
You can start a remote forwarding on the remote machine using:
ssh.startRemoteForwarding("127.0.0.1", 8080, "127.0.0.1", 80);
Code language: CSS (css)
Similarly to local forwarding, you can request the remote side start the forwarding on a random port. This will be returned to you from the startRemoteForwarding method.
int randomPort = ssh.startRemoteForwarding("127.0.0.1", 0, "127.0.0.1", 80);
Code language: JavaScript (javascript)
Remote forwarding can be cancelled with:
ssh.stopRemoteForwarding("127.0.0.1", 8080);
Code language: CSS (css)
And all remote forwarding with:
ssh.stopRemoteForwarding();
Code language: CSS (css)