2013-01-08 16 views
7

Komenda Java - Jsch sudo.JSCH sudo su command "tty" error

Używam jsch i moim zadaniem jest, aby zalogować się do serwera i polecenia Uruchom jako następujący

sudo su - bumboo 

Korzystanie poniższy kod, jestem z powodzeniem w stanie połączyć się, ale gdy próbuję uruchomić polecenie to daje mi błąd sudo: sorry, you must have a tty to run sudo

Poniżej mój kod

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 w sudo.java dostępnych przykład oni powinni używać

// 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); 

ale gdy uruchamiam polecenie jak "sudo -S -p - su bamboo" wciąż daje mi ten sam błąd

Każda pomoc mile widziana.

Odpowiedz

10

on pracował dla mnie

String command = "sudo su - bumboo"; 
channel.setPty(true); 
Powiązane problemy