【发布时间】:2020-03-19 22:32:34
【问题描述】:
我可以在 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 客户端 - 但 curl 也给出错误)后,我得到以下异常:
ssl.SSLHandshakeException: Remote host closed connection during handshake
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
我必须在 Jsch 中进行哪些配置才能使其与 openssh 客户端完全相同?
【问题讨论】:
-
你可以在服务器上查看
/var/log/auth,可能有提示 -
您是否保持会话打开?不是垃圾回收吗?
-
因此会话似乎已设置,但是当我尝试打开与客户端的 https 连接(来自 java 或 curl)时,我收到握手错误。使用 ssh 命令设置隧道时,我没有收到这样的错误。
-
这是我的问题的答案吗?我不关注。
-
我不敢相信,您的
curl https://localhost:8000与ssh一起使用,它应该抛出类似curl: (51) SSL: no alternative certificate subject name matches target host name 'localhost'的东西