2014-07-21 42 views
4
java.util.Properties config = new java.util.Properties();    
config.put("StrictHostKeyChecking", "no"); 
session.setConfig(config); 

使用config.put(“StrictHostKeyChecking”,“无”)的在上面的代码中,为什么我们需要设置StrictHostKeyCheckingno同时连接到通过JSch API SFTP?什么是JSch

回答

3

你不应该实际设置它。通过这样做你会失去很多SSH/SFTP安全性。

该选项告诉JSch SSH/SFTP库不验证SSH/SFTP服务器的公钥。如果您不验证公钥,您很容易受到man-in-the-middle attacks的影响。当然,除非你在私人信任网络内连接(所以你不关心安全/加密)。

阅读有关SSH/SFTP主机密钥:
https://www.symantec.com/connect/articles/ssh-host-key-protection
https://winscp.net/eng/docs/ssh_verifying_the_host_key

1
  • StrictHostKeyChecking:问|是|否 默认值:ask 如果此属性设置为yes'', jsch will never automatically add host keys to the $HOME/.ssh/known_hosts file, and refuses to connect to hosts whose host key has changed. This property forces the user to manually add all new hosts. If this property is set to否, jsch会自动将新主机密钥添加到用户已知主机 文件。如果这个属性设置为“ask”,只有在用户已经确认 这是他们真正想要做的事情之后,新的主机密钥才会被 添加到用户已知的主机文件中,并且jsch将拒绝将 连接到主机其主机密钥已更改。