Java is the Jsch sudo team.
I use Jsch, and my task is to log in to the server and run the command as shown below.
sudo su - bumboo
Using the following code, I can successfully connect, but when I try to run the command, it gives me a sudo: sorry, you must have a tty to run sudo error sudo: sorry, you must have a tty to run sudo
Below is my code
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 in the available sudo.java example they advise using
but when I run a command like "sudo -S -p - su bamboo" , it still gives me the same error
any help appreciated.
d-man
source share