Using JAVA intercepting Jsch prompt for entering password in UNIX shell
The JSCH website gives you an example on this very issue. The idea is to write the password to the OutputStream
which represents the "write" end of the ssh connection.The relevant code block:
((ChannelExec)channel).setCommand("sudo -S -p '' "+command);InputStream in=channel.getInputStream();OutputStream out=channel.getOutputStream();((ChannelExec)channel).setErrStream(System.err);channel.connect();out.write((sudo_pass+"\n").getBytes());out.flush();