我可以在Ubuntu中建立一个端口转发会话,如下所示:
ssh -L 8000:dev.mycompany.com:443 jump.mycompany.com
现在我想用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);
}
}然而,在设置隧道并尝试使用RestTemplate (Spring HTTP Client --但curl也给出一个错误)连接到它之后,我得到了以下异常:
ssl.SSLHandshakeException: Remote host closed connection during handshake
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)我必须在Jsch中配置什么才能使它与openssh客户端完全一样?
发布于 2020-03-19 21:05:16
我想,您正在尝试连接到一个不可公开的https get服务器。
端口转发可以工作,但https在localhost:8000上不起作用,因为证书是用于dev.mycompany.com而不是localhost。
您可以通过在hosts文件中添加一个条目来作弊。
127.0.0.1 dev.mycompany.com但可能尝试socks5更容易一些。
ssh jump.mycompany.com -D 8005然后在浏览器中进行设置(firefox示例):
选择:手动配置代理:
Socks主机: localhost
端口: 8005
Socks5
https://stackoverflow.com/questions/60757179
复制相似问题