title: Sending commands to remote server through ssh by Java with JSch
body: <p>I'm trying to set up a class so that I can ssh into a remote server (I have the IP, username, and password) and then send a command like <code>echo &quot;test&quot;</code> and then receive back the output (e.g., &quot;test&quot;). I'm using JSch to do this but I don't understand how to do it.</p>
  <pre><code>import com.jcraft.jsch.*;
  
  public class ConnectSSH {
  
  public int execute (String command) {
      
      JSch jsch   = new JSch();
      String ip   = &quot;00.00.00.00&quot;;
      String user = &quot;root&quot;;
      String pass = &quot;password&quot;;
      int port    = 22;
  
      Session session = jsch.getSession(user, ip, port);   
      session.setPassword(pass);
      session.connect();
  
      ...
  </code></pre>
  <p>I'm stuck after connecting.</p>