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 [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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

The OP says he is using key based authentication - the prompt is for the key passphrase not the SSH login prompt.
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 :/
Can you recreate the key file without a password?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.