简体   繁体   English

可以使用Java打开SSH隧道吗?

[英]Possible to open a SSH tunnel using Java?

I want to open up a SSH tunnel in a Java program, so that the rest of the system will also have access to the connection (eg if I forward a port for a database to the localhost I should be able to open the database in another program)... In other words what I need to do it to create a Java wrapper for something like the unix command ssh. 我想在Java程序中打开SSH隧道,以便系统的其余部分也可以访问连接(例如,如果我将数据库的端口转发到localhost,我应该能够在另一个数据库中打开数据库程序)...换句话说,我需要做的就是为unix命令ssh创建一个Java包装器。 However I need the program to be cross platform, so if possible I would like to use a library from Java. 但是我需要程序是跨平台的,所以如果可能的话我想使用Java库。

Is this possible (I have been looking at different libraries, but have not been able to create the tunnel so the rest of the system can use it yet) 这是可能的(我一直在查看不同的库,但是无法创建隧道,因此系统的其余部分可以使用它)

I had a success with article from beanizer based on Jcraft's Jsch. 我在基于Jcraft的Jsch的beanizer文章中取得了成功。 Here are more details: http://www.beanizer.org/site/index.php/en/Articles/Java-ssh-tunneling-with-jsch.html 以下是更多详细信息: http//www.beanizer.org/site/index.php/en/Articles/Java-ssh-tunneling-with-jsch.html

The JSch library definitely makes this easy and supports port forwarding: JSch库肯定使这很容易,并支持端口转发:

JSch jsch = new JSch();
Session session = jsch.getSession(user, host);
session.setPassword(password);
session.connect(timeout);
session.setPortForwardingL(listenPort, destHost, destPort);

也许是Jsch

我一直在使用Ganymede SSH-2取得了巨大的成功,实际上是第一次工作,令我惊讶。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM