Playing with Play Framework and JSch – Java Secure Channel


I’m gonna show you how to use the the Java library JSch – Java Secure Channel to connect to a server and send SSH commands to a UNIX shell and then return the output to our webpage. I’m using Play Framework to develop this webapp. If you want to know more about Play Framework just visit

A little bit about JSch:

JSch is a pure Java implementation of SSH2.
JSch allows you to connect to an sshd server and use port forwarding, X11 forwarding, file transfer, etc., and you can integrate its functionality into your own Java programs. JSch is licensed under BSD style license.

You can find more information about the library in

Case scenario:

I want to send a SSH command to an UNIX server via some Java class. I want to the output of this command that I sent is shown in the user’s screen through the web browser.

Our environment uses a Private Key to allow SSH connections between one machine to another. In the code snippets you will see that the keys are passed through the method

1st: the code snippet for the controller

2nd: the code snippet for the controller

Output of the command being displayed in a web browser:


That’s it! See ya!