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);
session.setPassword("password");
// Skip host-key check
session.setConfig("StrictHostKeyChecking", "no");
session.connect();
System.out.println("Connected...");
session.disconnect();
} catch (JSchException e) {
e.printStackTrace();
}
}
}
Maven Dependencies
<dependencies>
<dependency>
<groupId>com.jcraft</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
</dependency>
</dependencies>
Latest posts by Wayan (see all)
- How do I get number of each day for a certain month in Java? - September 8, 2024
- How do I get operating system process information using ProcessHandle? - July 22, 2024
- How do I sum a BigDecimal property of a list of objects using Java Stream API? - July 22, 2024