How do I connect to ssh server using JSch?

JSch is a pure Java implementation of SSH-2. SSH (Secure Shell) is a cryptographic network protocol for operating network services securely over an unsecured network. The following code snippet shows you how to open a connection to an ssh server.

package org.kodejava.jsch;

import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;

public class SSHConnect {
    public static void main(String[] args) {
        try {
            JSch jSch = new JSch();
            Session session = jSch.getSession("demo", "localhost", 22);

            // Skip host-key check
            session.setConfig("StrictHostKeyChecking", "no");
        } catch (JSchException e) {

Maven Dependencies


Maven Central

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.