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
try(SshClient ssh = new SshClient("localhost",
22,
"lee",
new SshClientContext().setBannerDisplay(display),
"xxxxxx".toCharArray())) {
}
Alternatively, you could extend SshClient with your own class and configure the BannerDisplay instance by overriding the SshClient's protected configure method.
protected void configure(SshClientContext sshContext) {
sshContext.setBannerDisplay(new BannerDisplay() {
@Override
public void displayBanner(String message) {
System.out.println(message);
}
});
}