Error while running ssh command in java

817 views Asked by At

I'm trying to run ssh command in Eclipse this way

ExpectJ exp = new ExpectJ();    
Spawn s = exp.spawn("ssh [email protected]");
. . . 
. . . 
. . . 

But i get this as the error-

Pseudo-terminal will not be allocated because stdin is not a terminal.

If i try doing it the following way,

Spawn s = exp.spawn("ssh -t -t [email protected]");

and execute,i get this error

tcgetattr: Invalid argument

also,the code executes only half and i get this message-

Killed by signal 15.

and finally i face a timeout exception

Any Suggestions? I'm not sure what those error messages mean.

2

There are 2 answers

0
hari On BEST ANSWER

I can use the in-built method!! Never realized that even existed.

s = exp.spawn(hostName, sshPort, userName, userPassword);
4
Kevin On

I'm not sure why you're getting the errors you're seeing, but I can say when I've needed to do ssh/scp etc. I've used this library: http://www.jcraft.com/jsch/ and it's worked very well for me.