List of usage examples for org.apache.commons.net.ssh.connection Session startShell
Shell startShell() throws ConnectionException, TransportException;
From source file:examples.ssh.RudimentaryPTY.java
public static void main(String... args) throws IOException { SSHClient ssh = new SSHClient(); ssh.loadKnownHosts();/* ww w .ja v a 2 s .co m*/ ssh.connect("localhost"); Shell shell = null; try { ssh.authPublickey(System.getProperty("user.name")); Session session = ssh.startSession(); session.allocateDefaultPTY(); shell = session.startShell(); new Pipe("stdout", shell.getInputStream(), System.out) // .bufSize(shell.getLocalMaxPacketSize()) // .start(); new Pipe("stderr", shell.getErrorStream(), System.err) // .bufSize(shell.getLocalMaxPacketSize()) // .start(); // Now make System.in act as stdin. To exit, hit Ctrl+D (since that results in an EOF on System.in) // This is kinda messy because java only allows console input after you hit return // But this is just an example... a GUI app could implement a proper PTY Pipe.pipe(System.in, shell.getOutputStream(), shell.getRemoteMaxPacketSize(), false); } finally { if (shell != null) shell.close(); ssh.disconnect(); } }