[[Manual]]

Here's a minimalistic example of Public Key Authentcation. It is adapted from JSCH examples, but I have stripped out the GUI etc.

 import com.jcraft.jsch.*;

 
 public class UserAuthPubKey{
  public static void main(String[] arg){

		String pubkeyfile="/home/cr/users/anand/.ssh/id_dsa";
		String passphrase="";
		String host="gs00", user="root";

 
    String pubkeyfile="/home/cr/users/anand/.ssh/id_dsa";
    String passphrase="";
    String host="gs00", user="root";
 
    try{
		JSch jsch=new JSch();
        jsch.addIdentity(pubkeyfile);
 //		jsch.addIdentity(pubkeyfile, passphrase);
		jsch.setKnownHosts("/home/cr/users/anand/.ssh/known_hosts");

      JSch jsch=new JSch();
      jsch.addIdentity(pubkeyfile);
 //   jsch.addIdentity(pubkeyfile, passphrase);
      jsch.setKnownHosts("/home/cr/users/anand/.ssh/known_hosts");
 
      Session session=jsch.getSession(user, host, 22);
      session.connect();

 
      Channel channel=session.openChannel("shell");

 
      channel.setInputStream(System.in);
      channel.setOutputStream(System.out);

 
      channel.connect();
    }
    catch(Exception e){
      System.out.println(e); e.printStackTrace();
    }
  } //end of main 
 } //end of class

---
Compile and run the example:

 anand@mkgg64:/home/nc/devel/src/jsch-0.1.37/examples$ CLASSPATH=$CLASSPATH:../dist/lib/jsch-0.1.37.jar javac UserAuthPubKey.java
 anand@mkgg64:/home/nc/devel/src/jsch-0.1.37/examples$  CLASSPATH=$CLASSPATH:../dist/lib/jsch-0.1.37.jar java UserAuthPubKey
 Last login: Wed Mar 12 17:15:27 2008 from 169.254.188.1
 [root@gs00 ~]#

Front page   Edit Diff Backup Upload Copy Rename Reload   New List of pages Search Recent changes   Help   RSS of recent changes