开发者

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

Hi is there an easy way to disable this host verification in j2开发者_JS百科ssh (assigning yes somewhere) that every time I connect to server I shoudn't type Yes ?


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.


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

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


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);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜