How can I display the Authentication Banner

Some SSH servers are configured to show an authentication banner to the user prior to authentication.

If you want to display this in your own application you can configure a BannerDisplay callback on the client’s context.

First, implement BannerDisplay interface, in this simple example we will just write the message to System.out.

BannerDisplay display = new BannerDisplay() { 
   @Override 
   public void displayBanner(String message) { 
      System.out.println(message); 
   } 
};

Next, we just have to configure this on the SshClientContext for each connection. The simplest way of doing this is to create and pass a SshClientContext instance to your SshClient

SshClientContext ctx = new SshClientContext();
ctx.setBannerDisplay(display);

try (SshClient ssh = SshClientBuilder.create()
		.withHostname("localhost")
		.withPort(2222)
		.withUsername("root")
		.withPassword("xxxx")
		.withSshContext(ctx)
		.build()) {