問題,表面的意思就是jsch驗證失敗,經過探索和實驗,可能的原因是以下2條:
- 你所使用的用戶不能進行遠程登錄,比如CentOS6,默認root不能進行遠程登錄,這一點需要引起注意
- linux服務器的配置文件
/etc/ssh/sshd_config 中 GSSAPIAuthentication 的值應該是 yes
- 在路徑 /etc/ssh/sshd_config 文件中,PermitRootLogin yes 把這一行通過註釋取消掉,也就是允許root遠程登錄。
- 在路徑
/etc/ssh/sshd_config 中 將GSSAPIAuthentication 修改爲 no, 或者在java代碼中增加
session.setConfig("userauth.gssapi-with-mic", "no"),同時不要忘了 session.setConfig("StrictHostKeyChecking", "no"); - 如果想加快SSH的登錄的速度,可以把路徑
/etc/ssh/sshd_config 文件中 UseDNS yes 修改爲 no
- 重啓sshd服務,service sshd restart