运行命令时code>,答案来自第二台机器,而不是我预期的第三台机器。我想知道是否有另一个库有助于使这项工作或我使用错误的JSch。I got connection, however when I run a command using object session, the answer is from the second machine not from the third machine as I expected. I would like to know if there is another library that helps to make this work or I'm using wrong JSch.推荐答案当然,如果你设置 rhost =localhost,连接将到达SSH服务器,而不是资源服务器。 输入正确的主机名,这应该没问题。 (我这样做了一次。)Of course, if you set rhost = "localhost", the connection will arrive at the SSH server, and not at the "Resource" server.Put the right host name in, and it should be no problem. (I did this once.)如果你想从JSch做两个连接,而不是做本地端口转发,然后连接到这个转发端口,你可以使用我的 ProxySSH 类,找到在JSch wiki中。 (我也是这样做的,就像你在那里一样。)If you want to do both connections from JSch, instead of doing a local port forwarding and then connecting to this forwarded port, you can use my ProxySSH class, to find in the JSch wiki. (I did this, too, in a similar situation like you have there.) 这篇关于通过Java中的SSH隧道运行远程命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!