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 more than novice in Linux. Nevertheless, I need to create a Java Web Service hosting in apache server in a Linux system. The Web service must use ssh to connect to a remote machine, create a txt file, execute a prog.exe (compiled C program in MPI) and then retrieve and return a single output value. The only thing that I do not know is how to connect remotely with the Web Service. In a shell will use something like:

ssh username@remotemachine

and then we will get a prompt for password. Is it possible to send the password along with the ssh command? I have read that it is possible to connect in one shot with public/private keys but this project is my Master Thesis one and as a result, the machines are these of the uni. So, I do not want to mess with the technicians because most of the times simple do not help at all.

Thanks very much

share|improve this question

2 Answers 2

up vote 0 down vote accepted

Most Ssh clients will recognize the following

ssh username@remotemachine -pw'YourPassword'

However, I used GanymedeSSH for Java and it had a method like this:

conn = new Connection(servername, 22);
conn.connect();
conn.authenticateWithPassword(username, password);
session = conn.openSession();

And as long as you keep reference to your session, you will be able to use it to execute commands on the remote machine.

share|improve this answer
    
thanks very much! but I take an error: Bad port 'wpassword'. W is from the -pw –  Johnis Agorgianitis Mar 3 '11 at 13:02
    
So, I will look the second option. Thanks a lot –  Johnis Agorgianitis Mar 3 '11 at 13:06
    
With GanymedeSSH is actually quite easy to connect thanks a lot !! –  Johnis Agorgianitis Mar 20 '11 at 22:49

You could use the library Jaramiko to get over the problem (instead of calling ssh externally).

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.