问题描述
我想创建一个从Windows系统到使用RSA令牌密码进行身份验证的Linux机器的连接,并且我想运行shell命令并从Java代码获取输出.使用腻子登录该Linux系统时,请执行以下步骤:
I want to create a connection from a Windows system to a Linux machine which uses RSA token Passcode for authentication and I want to run shell commands and get the output from the Java code. When logging into that Linux system using putty has the following steps:
- 输入IP和端口并连接
- 在PuTTY终端中输入用户名,询问登录为:"
- 输入PASSCODE,然后输入RSA SecurID
我已经尝试使用Jsch
包进行连接,但无法连接.我还尝试了一个jcabi-ssh
( http://ssh.jcabi.com/)作为包装器Jsch
.他们似乎都不适合我.
I have already tried connecting using Jsch
package and it doesn't connect. I also tried a jcabi-ssh
(http://ssh.jcabi.com/) which a wrapper for Jsch
. None of them seem to work for me.
我使用Jsch
软件包使用以下代码
I used the following code using the Jsch
packages
String host = "xxx";
String user = "xxx";
String password;
Scanner scanner = new Scanner (System.in);
System.out.println("Enter rsa token: ");
password = scanner.nextLine();
Session session = jsch.getSession(user, host, 2222);
session.setPassword(password);
session.connect();
我收到以下错误消息:
com.jcraft.jsch.JSchException: UnknownHostKey: myservername. RSA key fingerprint is ba:2b:70:2f:4f:fa:f6:20:31:56:e0:e8:8b:16:46:c9
我找到了一个解决方案,有人说包括这部分代码,它将StrictHostKeyChecking设置为"no":
I found a solution by someone saying include this piece of code which sets StrictHostKeyChecking to "no":
java.util.Properties config = new java.util.Properties();
config.put("StrictHostKeyChecking", "no");
session.setConfig(config);
然后我的错误更改为:
com.jcraft.jsch.JSchException: Auth cancel
尝试使用其他jcabi-ssh
实现也会得到类似的结果.
Trying with that other jcabi-ssh
implementation gives similar results.
推荐答案
您正在寻找的是一个对话框,该对话框将在该时间点接受密码短语并建立连接.这是集成RSA SecureId所需要的- http://www.jcraft. com/jsch/examples/UserAuthPubKey.java.html
What you are looking for is a dialog which will accept the passphrase at that point in time and establish connection. Here is what you need to integrate RSA SecureId - http://www.jcraft.com/jsch/examples/UserAuthPubKey.java.html
这篇关于使用Java中的ssh2连接到由RSA SecurID保护的Linux系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!