Reputation: 119
Me and a colleague are developing an web application to control a computer cluster. This computer cluster lacks an API so we need to be able use the Linux shell to control and add "jobs" via bash scripts. Each user has a specific amount of time to run applications on the cluster so we need to be able to SSH onto the system using the users credentials so their users account gets used to submit the job.
The web app is written using Spring. We have done some research into executing commands via SSH using Java and found the Jcsh module. However our question is if there is a Spring module to do this. We where quite surprised that we could not find one since the SFTP module is already there and (correct me if i'm wrong) uses the same protocol.
Did we misread the documentation or is there no module to do this?
Many thanks!
Upvotes: 3
Views: 11339
Reputation: 515
I really don't think calling SSH directly by Spring is a good idea.
Since if you want to call the SSH directly, you'll need either store host's password into your application, or store the private key in your application(maybe this is better, since you can use Java's keystore to protect your private key)
Either way, you'll get the application able to do anything the host allowed(and since you can control the host's application by running command, I assume this use has lots of power).
This could be quite dangerous for the computer cluster.
If you indeed need to call the functions by SSH, I suggest you write a small native application(using python or Java, anything you like), and set the permission for your application can only execute this application, this is much safer.
So, it is sane to have SFTP support in Spring, for this is a very useful transport for data, but it is very very very dangerous to let your application can run SSH directly, even at home, believe me.
Upvotes: 3
Reputation: 1902
Jsch is indeed the best Java SSH implementation out there.
Sadly, Spring does not provide any integration with it. I personnally had to write custom plumbing to make use of it. It is a low level API but the project is well documentation with great exemples.
For a previous project, I wrote a template like API wrapper for the Jsch. Sadly I couldn't open source it.
Upvotes: 1