I am able to run ssh-keygen with code below, but i still unclear on how to execute command inside SSH-keygen.
import java.io.IOException;
import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteWatchdog;
public class ApacheRunSSHKEygen {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
try {
// String line = "AcroRd32.exe /p /h " + file.getAbsolutePath();
String line = "C:\\ExecuteSSH\\ssh-keygen.exe -N";
CommandLine cmdLine = CommandLine.parse(line);
DefaultExecutor executor = new DefaultExecutor();
//watchdog
executor.setExitValue(1);
ExecuteWatchdog watchdog = new ExecuteWatchdog(60000);
executor.setWatchdog(watchdog);
int exitValue = executor.execute(cmdLine);
}
catch (Exception exc){
System.out.println("error" + exc);/*handle exception*/}
}
}
the output is :
ssh-keygen: option requires an argument -- N
usage: ssh-keygen [options]
Options:
-a trials Number of trials for screening DH-GEX moduli.
-B Show bubblebabble digest of key file.
-b bits Number of bits in the key to create.
....... .......
-y Read private key file and print public key.
if the code and command is right, the output after that should prompted for passphrase. like below
Generating public/private rsa key pair.
Enter file in which to save the key (/cygdrive/c/Users/USER/.ssh/id_rsa):
Enter passphrase:
-N
option must be followed by an argument. If you want the command to prompt for a passphrase, don't include -N at all. – VGR