Java JSch 中 config.put("StrictHostKeyChecking", "no") 的用途是什么

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24859305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-14 15:15:10  来源:igfitidea点击:

What is use of config.put("StrictHostKeyChecking", "no") in JSch

javasshsftpjschpublic-key

提问by king Ramesh

java.util.Properties config = new java.util.Properties();            
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);

In above code why we need to set StrictHostKeyCheckingvalue as nowhile connection to SFTP through JSch API?

在上面的代码中,为什么我们需要将StrictHostKeyChecking值设置为nowhile 通过 JSch API 连接到 SFTP?

回答by Martin Prikryl

You should NOT set it actually. You lose much of the SSH/SFTP security by doing to.

你不应该实际设置它。这样做会失去大部分 SSH/SFTP 安全性。

The option tells the JSch SSH/SFTP library not to verify public key of the SSH/SFTP server. You are vulnerable to man-in-the-middle attacks, if you do not verify the public key. Of course, unless you are connecting within a private trusted network (so you do not care for security/encryption).

该选项告诉 JSch SSH/SFTP 库不要验证 SSH/SFTP 服务器的公钥。如果您不验证公钥,您很容易受到中间人攻击。当然,除非您在私人可信网络内连接(因此您不关心安全/加密)。

Read about SSH/SFTP host keys:
https://winscp.net/eng/docs/ssh_verifying_the_host_key

阅读有关 SSH/SFTP 主机密钥的信息:https:
//winscp.net/eng/docs/ssh_verifying_the_host_key

回答by liaozq

StrictHostKeyChecking values: ask | yes | no

StrictHostKeyChecking 值:询问 | 是 | 不

default: ask

默认:询问

If this property is set to yes, JSch will never automatically add host keys to the $HOME/.ssh/known_hostsfile, and refuses to connect to hosts whose host key has changed. This property forces the user to manually add all new hosts.

如果此属性设置为yes,JSch 将永远不会自动将主机密钥添加到$HOME/.ssh/known_hosts文件中,并拒绝连接到主机密钥已更改的主机。此属性强制用户手动添加所有新主机。

If this property is set to no, JSch will automatically add new host keys to the user known hosts files.

如果此属性设置为no,JSch 将自动将新的主机密钥添加到用户已知的主机文件中。

If this property is set to ask, new host keys will be added to the user known host files only after the user has confirmed that is what they really want to do, and JSch will refuse to connect to hosts whose host key has changed.

如果此属性设置为ask,只有在用户确认这是他们真正想要做的事情后,新的主机密钥才会添加到用户已知的主机文件中,并且 JSch 将拒绝连接到主机密钥已更改的主机。