我需要将本地端口3308一直转发到3306的my SQL DB。
ssh -L 3308:localhost:3307 username@jumpbox "ssh -L 3307:mysqlDB:3306 username@server"
或者在我的本地计算机上运行第一部分,然后在jumpbox上运行第二部分。两者都可以正常工作,我可以连接到我的本地主机:3308。
JSch jsch = new JSch();
jsch.addIdentity("~/.ssh/id_rsa");
Session session = jsch.getSession("username", "jumpbox");
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
int assinged_port = session.setPortForwardingL(3308, "localhost", 3307);
Session mysqlSession = jsch.getSession("username", "server", assinged_port);
mysqlSession.setConfig("StrictHostKeyChecking", "no");
mysqlSession.connect(); // Connection timed out here
mysqlSession.setPortForwardingL(3307, "mysqlDB", 3306);
第一个连接已完成,但第二个连接超时。
线程“main”com.jcraft.jsch.JSchException:java.net.ConnectException:操作超时(连接超时)