1

I am trying to use j2ssh SshClient without success.

I am trying to open a connection using private RSA key + passphrase. I found something which I am not sure is the write approach:

Properties properties = new Properties();
properties.put("Passphrase", "xyz");
properties.put("PrivateKey", "sftp_rsa");
properties.put("Username", "user");
properties.put("StrictHostKeyChecking", "no");
publicKeyAuthenticationClient.setPersistableProperties(properties);
int result = ssh.authenticate(publicKeyAuthenticationClient);

I am using the setPersistableProperties method to load a Properties object that hold the relevant data. I have set the PrivateKey to the file name , and Passphrase to the relevant Passphrase.

Something else is I get a prompt of:

The host hostname.host,1.1.1.1 is currently unknown to the system
The host key fingerprint is: 100: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
Always option disabled, host file is not writeable
Do you want to allow this host key? [Yes|No]

which I have tries to remove using the StrictHostKeyChecking property set to "no". (Without success of course)

Any idea??

Thanks!

Tomer
  • 2,398
  • 1
  • 23
  • 31

1 Answers1

2

the SshClient.connect method takes an HostKeyVerification object as the second argument, one of the implementations is IgnoreHostKeyVerification, you can use it like:

SshConnectionProperties props = new SshConnectionProperties();
props .setHost(server);
props .setPort(port);
sshClient.connect(props , new IgnoreHostKeyVerification());

//this is your code
Properties properties = new Properties();
properties.put("Passphrase", "xyz");
properties.put("PrivateKey", "sftp_rsa");
properties.put("Username", "user");
properties.put("StrictHostKeyChecking", "no");
publicKeyAuthenticationClient.setPersistableProperties(properties);
int result = sshClient.authenticate(publicKeyAuthenticationClient);

i am not sure if this fix your issue but i think it might be it.

Max
  • 711
  • 1
  • 10
  • 27