public class KeepAlive { public static void main(String... args) throws IOException, InterruptedException { DefaultConfig defaultConfig = new DefaultConfig(); defaultConfig.setKeepAliveProvider(KeepAliveProvider.KEEP_ALIVE); final SSHClient ssh = new SSHClient(defaultConfig); try { ssh.addHostKeyVerifier(new PromiscuousVerifier()); ssh.connect(args[0]); ssh.getConnection().getKeepAlive().setKeepAliveInterval(5); //every 60sec ssh.authPassword(args[1], args[2]); Session session = ssh.startSession(); session.allocateDefaultPTY(); new CountDownLatch(1).await(); try { session.allocateDefaultPTY(); } finally { session.close(); } } finally { ssh.disconnect(); } } }