Loading...

Maven

<dependency>
	<groupId>com.jcraft</groupId>
	<artifactId>jsch</artifactId>
	<version>0.1.54</version>
	<type>jar</type>
</dependency>

Authentication

You might experience the problem, that the your running machine didn’t know your the SSH Key. To avoid this behavior, you can supply your know_hosts file or do authentication with password only.

Supply known_hosts file

String knownHostsFilename = "/home/tan/.ssh/known_hosts";
jsch.setKnownHosts(knownHostsFilename);

Use SSH key for authentication

jsch.addIdentity("/home/tan/.ssh/id_dsa"); //without passwd
jsch.addIdentity("/home/tan/.ssh/id_dsa", "secret"); //with passwd

Override SSH Key behavior

Disable strict host key checking

Properties config = new Properties();
config.put("PreferredAuthentications", "password");
config.put("StrictHostKeyChecking", "no");