Java library for an interactive SSH session (to be able to execute commands with multiple parts)?

I am currently using the library for SSH in Java, but it seems that I am not able to make multi-part commands (for example, if I do passwd user, I have no way to enter the password twice to change it, this forces you to start a new session every time, when you enter the command). I really need this functionality for the current application I'm working on, and there seem to be a lot of SSH libraries for Java, but I'm not sure which ones will allow this, as some don't seem to.

Any advice on a good library is welcome to take a look at this.

To close the patrol: if you try to close it, at least specify a thread that asks the same question as mine, and not just the general “what a good Java ssh library”, question

+5
source share
3 answers

I use the Ganymede SSH-2 library with great success. However, the password prompt should not appear in the application at all, it should be part of the agreement to establish a connection.

+2
source

After much searching, I found this: http://code.google.com/p/enchanter/ , which looks like exactly what I need, so I decided that I would post it here for reference

0
source

, "passwd user",

session.getStdin().write() refer following snipped 
connection = new Connection( host,port );
            connection.connect();
            // Authenticate
   boolean result = connection.authenticateWithPassword( username, password );
 Session session = connection.openSession();
session.requestPTY("bash");
session.execCommand( "passwd testuser" );
session.getStdin().write("newPassword\n".getBytes()); // //for new password
session.getStdin().write("newPassword\n".getBytes()); //for retype new password

 System.out.println( "ExitCode: " + session.getExitStatus() );
session.close();
connection.close();
0

All Articles