[英]Using root Commands with JSch (ssh)
我可以運行rm / home / user / Desktop / file之類的常規命令,但是當我無法運行root命令時。
我的意圖是配置一個運行如下命令的魷魚服務:apt-get install squid service squid start service
但是這些命令需要超級用戶身份驗證。
有誰知道如何解決? 謝謝
public void executarComandoSsh(Session session, String comando) {
try {
ChannelExec channel = (ChannelExec) session.openChannel("exec");
((ChannelExec) channel).setPty(true);
((ChannelExec) channel).setPtyType("vt100");
((ChannelExec) channel).setXForwarding(true);
System.out.println("Comando " + comando);
channel.setCommand(comando);
channel.setInputStream(null);
channel.setErrStream(System.err);
BufferedReader in = new BufferedReader(new InputStreamReader(channel.getInputStream()));
channel.connect();
String line = "";
while (true) {
while ((line = in.readLine()) != null) {
System.out.println("-- " + line);
}
break;
}
channel.disconnect();
session.disconnect();
} catch (JSchException | IOException ex) {
Logger.getLogger(ServidorNegocioImpl.class.getName()).log(Level.SEVERE, null, ex);
}
}
解決了..
我編輯了/ etc / sshd / sshd_config並設置了啟用root登錄:是的...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.