Simple SSH Tunnel in Java

I want to create an SSH tunnel in Java. I noticed quite a few Java SSH libraries on another post . Before I delve into each option, maybe someone can give me some code snippets on how they did it or at least tell me which client library will work best.

I only need tunneling. I don’t need things like file transfer, terminal emulation, etc. Are there a few lines of code that can redirect a port to a server to work on my localhost client adapter? Ideally, both the client and server will be in Java, but for now I will only agree on the client.

+12
java ssh tunnel
source share
2 answers

Well, as pointed out in another question, JSch is really a great choice and has a few examples here . The PortForwardingL.java class can be a good starting point.

+20
source share

You can do this with several libraries. My favorite ssh library inside the MindTerm package,

http://linuxmafia.com/pub/java/ISNetworks-MindTerm-1.2.1-SCP3.tar.gz

You can open a tunnel connection like this,

SSHSocketFactory fact = new SSHSocketFactory(sshHost, sshPort, new SSHPasswordAuthenticator(sshUser, sshPassword)); sock = fact.createSocket(host, port); 
+16
source share

All Articles