user615927
user615927

Reputation: 153

SSHtools disable Verifying host key[Yes/No] message?

Hi is there an easy way to disable this host verification in j2ssh (assigning yes somewhere) that every time I connect to server I shoudn't type Yes ?

Upvotes: 1

Views: 4030

Answers (3)

Pwdr
Pwdr

Reputation: 3781

Here is a snippet, just replace the parts from the example here.

  SshClient ssh = new SshClient();
  ssh.setSocketTimeout(30000);
  SshConnectionProperties props = new SshConnectionProperties();
  props.setHost(hostname);
  props.setPort(port);
  ssh.connect(props , new IgnoreHostKeyVerification()); // ignore unknown host warning
  // Create a password authentication instance
  PasswordAuthenticationClient pwd = new PasswordAuthenticationClient();
  pwd.setUsername(username);
  pwd.setPassword(password);     
  // Try the authentication
  int result = ssh.authenticate(pwd);

Upvotes: 0

François Fournier
François Fournier

Reputation: 316

If you don't want to validate the host, the following piece of code should do the job:

ssh.connect(hostname, new IgnoreHostKeyVerification());

Upvotes: 2

johnsyweb
johnsyweb

Reputation: 141908

In SSH, there is a configuration option:

StrictHostKeyChecking=no 

You can probably set this in j2ssh like this:

setConfig("StrictHostKeyChecking", "no")

Whether this is a good idea is left as an exercise for the reader.

Upvotes: 3

Related Questions