title: Using root Commands with JSch (ssh)
body: <p>I can run regular commands like rm /home/user/Desktop/file but when i cannot run root commands.</p>
  
  <p>My intent is to configure a squid service running commands like:
  apt-get install squid
  service squid start
  service</p>
  
  <p>but those commands require superuser authentication.</p>
  
  <p>Does anyone knows how to fix it? Thanks</p>
  
  <pre><code>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);
      }
  }
  </code></pre>