Hi,
Recently I have started using jsch.
Our setup here is like my server resides behind gateway. So first I need to
do ssh to gateway and from there I need to ssh to my server. I am using
following code.
package testPack;
import java.io.InputStream;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.Channel;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Session;
public class sshExample {
public static void main(String[] args) {
String host=xx.xx.xx.xx;
String user=user;
String password=password;
String command1=ssh tom...@yy.yy.yy.yy;
try{
java.util.Properties config = new java.util.Properties();
config.put(StrictHostKeyChecking, no);
JSch jsch = new JSch();
Session session=jsch.getSession(user, host, 22);
session.setPassword(password);
session.setConfig(config);
session.connect();
System.out.println(Connected);
Channel channel=session.openChannel(exec);
((ChannelExec)channel).setCommand(command1);
channel.setInputStream(null);
((ChannelExec)channel).setErrStream(System.err);
InputStream in=channel.getInputStream();
channel.connect();
byte[] tmp=new byte[1024];
while(true){
while(in.available()0){
int i=in.read(tmp, 0, 1024);
if(i0)break;
System.out.print(new String(tmp, 0, i));
}
if(channel.isClosed()){
System.out.println(exit-status: +channel.getExitStatus());
break;
}
try{Thread.sleep(1000);}catch(Exception ee){}
}
channel.disconnect();
session.disconnect();
System.out.println(DONE);
}catch(Exception e){
e.printStackTrace();
}
}
}
I am getting following error message :
Connected
Permission denied, please try again.
Permission denied, please try again.
Permission denied (publickey,gssapi-with-mic,password).
exit-status: 255
DONE
Can you please help me on this?
--
Thanks,
Chinmay Shepal
--
Master Java SE, Java EE, Eclipse, Spring, Hibernate, JavaScript, jQuery
and much more. Keep your Java skills current with LearnJavaNow -
200+ hours of step-by-step video tutorials by Java experts.
SALE $49.99 this month only -- learn more at:
http://p.sf.net/sfu/learnmore_122612 ___
JSch-users mailing list
JSch-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jsch-users