title: Simple SSH connect with JSch
body: <p>I am trying to make something from this simple example :</p>
  
  <p><a href="http://www.eridem.net/android-tip-021-ssh-execute-remote-commands-with-android">SSH, execute remote commands with Android</a></p>
  
  <p>I just want to see if I can connect from my android phone to a linux server using SSH but it doesn't work...</p>
  
  <p>Here is my main code :</p>
  
  <pre><code>package com.example.ssh;
  
  import java.util.Properties;
  import com.jcraft.jsch.JSch;
  import com.jcraft.jsch.Session;
  import android.os.Bundle;
  import android.app.Activity;
  
   public class MainActivity extends Activity {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
  
      try
      {
          JSch jsch = new JSch();
            Session session = jsch.getSession("root","192.168.0.26", 22);
            session.setPassword("xxxxx");
  
            // Avoid asking for key confirmation
            Properties prop = new Properties();
            prop.put("StrictHostKeyChecking", "no");
            session.setConfig(prop);
  
            session.connect();
  
      }
      catch (Exception e)
      {
        System.out.println(e.getMessage());
      }
  }
  }
  </code></pre>
  
  <p>What did I do wrong ? I have no error messages and I don't see any SSH connection on my Linux. I added the libraries jsch and jzlib. I have no problem to get connect with a putty session.</p>
  
  <p>EDIT1 : In fact, I found an error which explain why it doesn't work even if I don't know how to resolve the problem. The error is :</p>
  
  <p>android.os.NetworkOnMainThreadException</p>
  
  <p>so it seems to mean that the app can't perform a networking operation on its main thread...</p>