Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I am looking for a simple way to execute the ssh command in my java program. Basically I gather user input and based on their choices on hosts I want to execute the ssh command and let the linux shell command take over. I have the feeling that a scripting language would be better suited but this is urgent and I have no experience in scripting. I have tried something like the following based on info I gathered on the site:

Runtime.getRuntime().exec("ssh myusername@ipaddress");

However it doesn't seem to work Thanks in advance

share|improve this question
    
What is the error? What do you see? The only thing I can tell is that there is no problem in calling ssh from Java using Runtime.getRuntime() –  Guillaume Polet Mar 13 '12 at 17:21

2 Answers 2

up vote 0 down vote accepted

Have you taken a look at Jsch? It seems to be what you need.

Scripting is super easy as well. Just take all the commands you would execute on a terminal and put them in the script. send in the arguments(usersnames/password,hosts,etc..) and you're good to go.

Either way, good luck.

share|improve this answer
1  
lots of Jsch examples here: jcraft.com/jsch/examples –  sw1nn Mar 13 '12 at 17:20
    
So I have implemented jsch into my code. However the interaction with the host server is done in the java program. What I want is to: one read an xml file that contains multiple hosts( name, ipaddress, password) prompt user for choices. Once I gather all this info all I want is execute the ssh command with the values and exit the program. This doesn't seem to be the case with jcraft –  Switch Apr 13 '12 at 16:56

For a free component, look at Ganymed SSH.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.