1

嗨,有没有一种简单的方法可以在 j2ssh 中禁用此主机验证(在某处分配 yes),每次我连接到服务器时我都不应该输入 Yes ?

4

3 回答 3

2

在 SSH 中,有一个配置选项:

StrictHostKeyChecking=no 

您可能可以这样设置j2ssh

setConfig("StrictHostKeyChecking", "no")

这是否是一个好主意留给读者作为练习。

于 2011-03-16T10:02:07.953 回答
2

如果您不想验证主机,以下代码应该可以完成这项工作:

ssh.connect(hostname, new IgnoreHostKeyVerification());
于 2012-07-20T15:24:16.990 回答
0

这是一个片段,只需替换此处示例中的部分即可。

  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);
于 2014-04-14T11:43:20.037 回答