Java SSH Client by Example

Java SSH Client by Example

Maverick Synergy Java SSH Client Examples

Introduction to the Java SSH Client API

The Maverick Synergy Java SSH Client is a third-generation API now with over 18 years of development. In our examples below, we have tried as much as possible to create working examples that can be run and understood by an experienced Java programmer. Some source attributes may need to be changed, such as hostnames and IP addresses. If you would like a specific example, then please get in touch via our forums

Maverick Synergy is available under the LGPL open-source with regular updates and maintenance releases made in line with our open-source release policy. Priority support and instance hotfixes are available under a commercial subscription agreement. Our developers have over 18 years of experience working with and supporting Java SSH solutions.

Quick Start

Copy and paste these quick examples to get started. Did you already download or setup the API via Maven? If not Download Now.

Create a Java SSH client and authenticate with your password.

   SshClient ssh = new SshClient("localhost", 22, "lee", "mypassword".toCharArray());

Execute a command.

   ssh.executeCommand("echo 'I was here!' > visited.txt");

Download a file.

   ssh.getFile("visited.txt", new File("visited.txt"));

Load a private key from file.

   SshKeyPair pair = SshKeyUtils.getPrivateKey(new File(".ssh/id_rsa"), "mypassphrase");

Programmatically enable logging.

   Log.enableConsole(Level.DEBUG);