Reputation: 121
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 [email protected] "});
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.
Upvotes: 2
Views: 359
Reputation: 3250
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.
Upvotes: 1