2014-07-21 44 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將拒絕將 連接到主機其主機密鑰已更改。