2

I'm trying to write a helper application that will feed off a list of servers I need to connect to, then execute an SSH connect command.

I'm currently trying this:

Process p = Runtime.getRuntime().exec(new String[]{"bash","-c","ssh user@stackoverflow.com "});

Which does what it's supposed to, it executes the command. My servers are all key based authentication only, so SSH responds by asking for the key passphrase. At this stage, you can't actually interact SSH to enter the password.

Any ideas how I can work around this?

Thanks in advance!

Edit: For clarity, I need a way to either spin off to a new SSH process that the user can interact ssh with properly.

Mike McCormick
  • 121
  • 1
  • 1
  • 9

1 Answers1

1

I don't think shelling out to a child SSH process will work. IIRC the password prompt is sent to the controlling TTY, so a spawning process won't be able to supply it using stdin/stdout redirection.

Given that, look at a Java SSH client library, like http://www.jcraft.com/jsch/. Here's an SO post with more info: SSH library for Java.

Community
  • 1
  • 1
schtever
  • 3,210
  • 16
  • 25
  • 1
    The OP says he *is* using key based authentication - the prompt is for the key passphrase not the SSH login prompt. – Rodney Jul 31 '15 at 16:33
  • Yeah, that's pretty much the issue. I've tried having it fire open a new screen session, but even that doesn't work. I *really* don't want to implement a whole SSH library for this :/ – Mike McCormick Aug 05 '15 at 15:58
  • Can you recreate the key file without a password? – schtever Aug 05 '15 at 16:14