I can establish a port forwarding session in Ubuntu as follows:
ssh -L 8000:dev.mycompany.com:443 jump.mycompany.com
now I'd like to emulate this with Jsch:
public static void openTunnel() {
JSch jsch = new JSch();
String privateKey = "~/.ssh/id_rsa";
try {
jsch.addIdentity(privateKey);
log.info("Connecting to {}@{}", getJumpUser(), getJumpServer());
Session session = jsch.getSession(getJumpUser(), getJumpServer(), 22);
session.connect();
session.setPortForwardingL(8000, getHost(), 433);
} catch (JSchException e) {
log.error("", e);
}
}
However I get the following exception after the tunnel is set up, and trying to connect to it with RestTemplate (Spring HTTP Client - but curl gives an error as well):
ssl.SSLHandshakeException: Remote host closed connection during handshake
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
What do I have to confiugre in Jsch so that it does exactly the same as the openssh client?
I suppose, you're trying to get a connection to a https webserver that's not public available.
The port forwarding works, BUT https will not work on localhost:8000, because the certificate is for dev.mycompany.com and not localhost.
You can cheat, by adding an entry into your hosts file.
127.0.0.1 dev.mycompany.com
But probably it's easier to try socks5.
ssh jump.mycompany.com -D 8005
And then setting in your browser (sample for firefox):
Select: Manual proxy configuration:
Socks Host: localhost
Port: 8005
Socks5
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With