JSCH sudo su comando erro “tty”
Comando Java - Jsch sudo.
Eu estou usando Jsch e minha tarefa é fazer o login no servidor e executar o comando da seguinte forma
sudo su - bumboo
Usando o seguinte código eu sou capaz de se conectar, mas quando tento executar o comando me dá errosudo: sorry, you must have a tty to run sudo
A seguir está meu código
public static Channel sudoBamboo(Session session, String sudo_pass) throws Exception {
ChannelExec channel = (ChannelExec) session.openChannel("exec");
//SUDO to bamboo user
String command = "sudo su - bumboo";
channel.setCommand(command);
//InputStream in = channel.getInputStream();
channel.setInputStream(null, true);
OutputStream out = channel.getOutputStream();
//channel.setErrStream(System.err);
channel.setOutputStream(System.out, true);
channel.setExtOutputStream(System.err, true);
//Test change
//channel.setPty(false);
channel.connect();
out.write((sudo_pass + "\n").getBytes());
out.flush();
return channel;
}
jsch em sudo.java exemplo disponível eles aconselharam usar
// man sudo
// -S The -S (stdin) option causes sudo to read the password from the
// standard input instead of the terminal device.
// -p The -p (prompt) option allows you to override the default
// password prompt and use a custom one.
((ChannelExec)channel).setCommand("sudo -S -p '' "+command);
mas quando eu corro comando como"sudo -S -p - su bamboo"
ainda me dá o mesmo erro
Qualquer ajuda apreciada.