[英]Interact with linux server using java JSCH
I have created java program using JSch class. 我已经使用JSch类创建了Java程序。 Program successfully execute the ( ls, cd, change
) commands. 程序成功执行了( ls, cd, change
)命令。 These commands dint need any inputs. 这些命令dint需要任何输入。 But while executing the /usr/ses/b/kr
command it require the password . 但是在执行/usr/ses/b/kr
命令时,需要输入密码 。
Can you please reply how I can send password to linux server using JSch . 您能回答我如何使用JSch向Linux服务器发送密码吗? Or there is any another way? 还是有其他方法?
((ChannelExec)channel).setCommand("/usr/ses/b/kr;");
You should set StrictHostKeyChecking property "no" and channel should be set shell.as following. 您应该将StrictHostKeyChecking属性设置为“ no”,并且将通道设置为shell。如下。
String username = "xxxyyyzzz";
String password = "aaabbbccc";
String host = "192.168.1.1"; // sample ip address
if(command.getText().toString() != ""){
JSch jsch = new JSch();
try {
session = jsch.getSession(username, host, 22);
session.setPassword(password);
Properties properties = new Properties();
properties.put("StrictHostKeyChecking", "no");
session.setConfig(properties);
session.connect(30000);
channel = session.openChannel("shell");
channel.setInputStream(bais);
channel.setOutputStream(baos);
channel.connect();
} catch (JSchException e) {
// TODO Auto-generated catch block
}
}
else{
//
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.