Connect to a linux system secured by RSA SecurID u

2019-05-26 01:59发布

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条回答
聊天终结者
2楼-- · 2019-05-26 02:48

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

查看更多
登录 后发表回答