2013-01-08 14 views
7

जावा - जेएसएच सुडो कमांड।JSCH sudo su कमांड "tty" त्रुटि

मैं Jsch और मेरे काम का उपयोग कर रहा सर्वर पर लॉगइन करें और आदेश को चलाने के लिए के रूप में मैं सफलतापूर्वक कनेक्ट करने में सक्षम हूँ, लेकिन जब मैं आदेश यह देता है चलाने का प्रयास मुझे sudo: sorry, you must have a tty to run sudo

त्रुटि निम्नलिखित कोड का उपयोग करना

sudo su - bumboo 

पीछा कर रहा है बाद

मेरी कोड है sudo.java उपलब्ध उदाहरण में

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 वे

0 का उपयोग करने की सलाह दी
// 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); 

लेकिन जब मैं "sudo -S -p - su bamboo" की तरह आदेश चला अभी भी मुझे एक ही त्रुटि

किसी भी मदद की सराहना की है देता है।

उत्तर

10

यह मेरे

String command = "sudo su - bumboo"; 
channel.setPty(true); 
के लिए काम किया
संबंधित मुद्दे