ssh - Jsch:基于隧道的 HTTPS
问题描述
我可以在 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 客户端完全相同?
解决方案
我想,您正在尝试连接到不公开的 https 网络服务器。
端口转发有效,但 https 在 localhost:8000 上无效,因为证书是 fordev.mycompany.com
而不是localhost
.
您可以通过在hosts
文件中添加条目来作弊。
127.0.0.1 dev.mycompany.com
但可能更容易尝试 socks5。
ssh jump.mycompany.com -D 8005
然后在浏览器中设置(firefox 示例):
选择:手动代理配置:
Socks 主机:localhost
端口:8005
Socks5
推荐阅读
- python - 如何在python中使用Pyqt5获取qlistwidget中项目的行号
- python - Python爬虫问题
- python - python脚本中的转义符号
- ruby-on-rails - Rails 和 kaminari -- 未定义的方法“total_pages”
- kotlin - 每个点击的列表视图在 kotlin lang 中不显示 Tost?
- java - 如何使用参数创建单个 get 方法以返回特定字段
- python-3.x - 如何在 python 中使用 selenium webdriver 移动到下一页直到结束
- android - 通过电子邮件共享PDF而不保存
- sql - 寻找一种解决方案以从 SQL 表中检索 1 或最大值的值
- webstorm - WebStorm 不允许我将项目放在 GitHub 上