Package com.jcraft.jsch

Examples of com.jcraft.jsch.JSch


        if(entry != null)
            session = entry.getSession();
        if(session == null || !session.isConnected()) {
            Message.verbose(":: SSH :: connecting to "+host+"...");
            try {
                JSch jsch=new JSch();
                if(port != -1)
                    session = jsch.getSession(username,host,port);
                else
                    session = jsch.getSession(username,host);
                if(pemFile != null) {
                    jsch.addIdentity(pemFile.getAbsolutePath(), pemPassword);
                }
                session.setUserInfo(new cfUserInfo(host,username,userPassword,pemFile,pemPassword,passFile));
                session.connect();
                Message.verbose(":: SSH :: connected to "+host+"!");
                setSession(username, host, port, session);
View Full Code Here


      String publicKeyPath = c.getString(Property.PUBLIC_KEY_FILE.getConfigName());
      publicKeyPath = (publicKeyPath == null && privateKeyPath != null) ?
                privateKeyPath + ".pub" : publicKeyPath;
      if(privateKeyPath != null && publicKeyPath != null) {
        KeyPair pair = KeyPair.load(new JSch(), privateKeyPath, publicKeyPath);
        if (pair.isEncrypted()) {
          throw new ConfigurationException("Key pair is encrypted");
        }
        if (!sameKeyPair(new File(privateKeyPath), new File(publicKeyPath))) {
          throw new ConfigurationException("Both keys should belong " +
View Full Code Here

   *   private key
   */
  public static Map<String,String> generate(String passPhrase)
  throws JSchException {
    com.jcraft.jsch.KeyPair pair = com.jcraft.jsch.KeyPair.genKeyPair(
        new JSch(),  com.jcraft.jsch.KeyPair.RSA);
    if (passPhrase != null) {
      pair.setPassphrase(passPhrase);
    }

    ByteArrayOutputStream publicKeyOut = new ByteArrayOutputStream();
View Full Code Here

   *
   * @return a SSH Credential generated and encrypted using a randomly generated password
   * @throws CredentialStoreException
   */
  public SSHCredential generateCredential(String tokenId) throws CredentialStoreException {
        JSch jsch=new JSch();
        try {
            KeyPair kpair=KeyPair.genKeyPair(jsch, KeyPair.RSA);
            File file;
     
        file = File.createTempFile("id_rsa", "");
View Full Code Here

        sshd.setCommandFactory(new ScpCommandFactory());
        sshd.setShellFactory(new EchoShellFactory());
        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();

        JSch sch = new JSch();
        sch.setLogger(new Logger() {
            public boolean isEnabled(int i) {
                return true;
            }

            public void log(int i, String s) {
                System.out.println("Log(jsch," + i + "): " + s);
            }
        });
        session = sch.getSession("sshd", "localhost", port);
        session.setUserInfo(new UserInfo() {
            public String getPassphrase() {
                return null;
            }
View Full Code Here

        }
        return false;
    }

    protected Session createSession() throws JSchException {
        JSch sch = new JSch();
        sch.setLogger(new Logger() {
            public boolean isEnabled(int i) {
                return true;
            }

            public void log(int i, String s) {
                System.out.println("Log(jsch," + i + "): " + s);
            }
        });
        Session session = sch.getSession("sshd", "localhost", sshPort);
        session.setUserInfo(new UserInfo() {
            public String getPassphrase() {
                return null;
            }
View Full Code Here

        sshd.setPasswordAuthenticator(new BogusPasswordAuthenticator());
        sshd.start();
    }

    protected com.jcraft.jsch.Session getJschSession() throws JSchException {
        JSch sch = new JSch();
        sch.setLogger(new Logger() {
            public boolean isEnabled(int i) {
                return true;
            }

            public void log(int i, String s) {
                System.out.println("Log(jsch," + i + "): " + s);
            }
        });
        session = sch.getSession("sshd", "localhost", port);
        session.setUserInfo(new UserInfo() {
            public String getPassphrase() {
                return null;
            }
            public String getPassword() {
View Full Code Here

      e.printStackTrace();
    }
  }
 
  private void doWork() throws Exception{
    JSch jsch = new JSch();
    String fileName = "C:/Users/Stelk/workspace/jChains/src/main/conf/jChains.properties";
    File file = new File(fileName);
    FileInputStream fis = new FileInputStream(file);
   
    UserInfoImpl ui = new UserInfoImpl(this.prop);
                    
    jsch.addIdentity("C:\\cygwin\\home\\Stelk\\.ssh\\id_rsa");
    Session session =  jsch.getSession("root", "192.168.1.1", 22);
    session.setUserInfo(ui);
    session.connect();
    String command = "iptables -L INPUT -nv --line-numbers";
    try {
        Channel channel=session.openChannel("exec");
View Full Code Here

      }
   }

   @Override
   public Session create() throws Exception {
      JSch jsch = new JSch();
      session = jsch
            .getSession(loginCredentials.getUser(), hostAndPort.getHostText(), hostAndPort.getPortOrDefault(22));
      if (sessionTimeout != 0)
         session.setTimeout(sessionTimeout);
      if (loginCredentials.getPrivateKey() == null) {
         session.setPassword(loginCredentials.getPassword());
      } else if (loginCredentials.hasUnencryptedPrivateKey()) {
         byte[] privateKey = loginCredentials.getPrivateKey().getBytes();
         jsch.addIdentity(loginCredentials.getUser(), privateKey, null, emptyPassPhrase);
      } else if (agentConnector.isPresent()) {
         JSch.setConfig("PreferredAuthentications", "publickey");
         jsch.setIdentityRepository(new RemoteIdentityRepository(agentConnector.get()));
      }
      java.util.Properties config = new java.util.Properties();
      config.put("StrictHostKeyChecking", "no");
      session.setConfig(config);
      if (proxy.isPresent())
View Full Code Here

        // [localhost]:21000 ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgQDd \
        // fIWeSV4o68dRrKSzFd/Bk51E65UTmmSrmW0O1ohtzi6HzsDPjXgCtlTt3F \
        // qTcfFfI92IlTr4JWqC9UK1QT1ZTeng0MkPQmv68hDANHbt5CpETZHjW5q4 \
        // OOgWhVvj5IyOC2NZHtKlJBkdsMAa15ouOOJLzBvAvbqOR/yUROsEiQ==

        JSch jsch = new JSch();
        try {
            LOG.debug("Using '{}' for known hosts.", knownHostsFile);
            jsch.setKnownHosts(knownHostsFile);
            Session s = jsch.getSession("admin", "localhost", getPort());
            s.setConfig("StrictHostKeyChecking""ask");
            s.setConfig("HashKnownHosts""yes");
            s.setUserInfo(new UserInfo() {
                @Override
                public String getPassphrase() {
View Full Code Here

TOP

Related Classes of com.jcraft.jsch.JSch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.