我正在java中使用Jsch来建立到unix主机的连接,.I能够连接到unix host.The问题仍然是控制台和提示符再次询问密码。
附加代码。
package newcon;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.channels.Channel;
import java.util.Scanner;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;
import com.jcraft.jsch.UserInfo;
public class Conn {
public static void main(String args[]) {
String user = "XXXXXX";
String password = "xxxxxxx";
String host = "xxxxx";
int port = 22;
String command1="ls -ltr";
try {
java.util.Properties config = new java.util.Properties();
//config.put("StrictHostKeyChecking", "no");
config.put("StrictHostKeyChecking", "no");
JSch jsch = new JSch();
Session session=jsch.getSession(user,host, 22);
session.setPassword(password);
session.setConfig(config);
System.out.println("config:"+config);
session.connect();
System.out.println("Connected");
com.jcraft.jsch.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(i<0)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();
}
}
}有没有人能帮我弄清楚公钥和键盘交互密码。
这样,在我的提示符中不给出任何东西,它就会连接到主机。感谢一些人在上述问题上的帮助,
谢谢,尼基尔
发布于 2020-04-28 19:53:41
我不能说这是一个错误日志,
仍然附加了一个,我可以从我的控制台看到。
Kerberos用户名nudayaku: nuadayaku的Kerberos密码:
https://stackoverflow.com/questions/61478127
复制相似问题