Connect to a linux system secured by RSA SecurID using ssh2 in Java

匿名 (未验证) 提交于 2019-12-03 09:05:37

问题:

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:

  1. Enter IP and port and connect
  2. Enter username in the PuTTY terminal which asks "login as: "
  3. Enter PASSCODE where we enter RSA SecurID

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.

EDIT: 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(); 

I get the following error after it:

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

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); 

Then my error changed to:

com.jcraft.jsch.JSchException: Auth cancel 

Trying with that other jcabi-ssh implementation gives similar results.

回答1:

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



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!