在尝试将文件上传到我们的服务器时,我收到以下异常
com.jcraft.jsch.JSchException: Auth fail
at com.jcraft.jsch.Session.connect(Session.java:464)
at com.jcraft.jsch.Session.connect(Session.java:158)
at FtpService.transferFileToReciever(FtpService.java:80)
at FtpService.transferFileToReciever(FtpService.java:54)
at FtpService.transferFileToRecievers(FtpService.java:44)
at FtpService.transferSingeFile(FtpService.java:241)
at FtpService.main(FtpService.java:26)
Auth fail
来自源文件的函数 transferFileToReciever 部分是
JSch jsch = new JSch();
jsch.addIdentity("/root/.ssh/id_dsa");
Session session = jsch.getSession(username, host, 22);
session.setUserInfo(serverinfo);
session.connect(); //geting exception here
boolean ptimestamp = true;
密码有效,因为我可以使用 ssh 登录,但使用 JSCh 即使提供 key 、用户名和密码也无法使用。 使用带有 java 版本“1.6.0_25”的 id_dsa 键。 可能是什么错误?
找到其他类似的问题,但没有答案。 提前致谢。
最佳答案
追根溯源,我终于发现远程服务器上的授权 key 中没有添加dsa类型的公钥。附加相同的内容对我有用。
ssh 正在使用 rsa key ,导致我回顾我的代码。
谢谢大家。
关于java - "com.jcraft.jsch.JSchException: Auth fail"使用工作密码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17148948/