Creating your Server

Lee Painter

To build your server you need to extend the com.maverick.nio.Daemon class and implement its configure method. Within this method you create any number of SshContext instances which define the configuration for incoming connections. An SshContext is tied to a listening interface so therefore, if required, you can run different types of configuration within the same JVM. 


public class ExampleSSHD extends Daemon {

     static Logger log = LoggerFactory.getLogger(ExampleSSHD.clas

     public ExampleSSHD() {


     protected void configure(DaemonContext context) throws SshException, IOException {

          if (log.isInfoEnabled())

     "Configuring Example SSHD");


          SshContext sshContext = new SshContext(this);


          try {


                    new File("ssh_host_rsa_key"),

                    SshKeyPairGenerator.SSH2_RSA, 2048);



                    new File("ssh_host_dsa_key"),

                    SshKeyPairGenerator.SSH2_DSA, 1024);



                    new File("ssh_host_key_ecdsa_256"),

                    SshKeyPairGenerator.ECDSA, 256);



                    new File("ssh_host_key_ecdsa_384"),

                    SshKeyPairGenerator.ECDSA, 384);



                    new File("ssh_host_key_ecdsa_521"),

               SshKeyPairGenerator.ECDSA, 521);

          } catch (InvalidPassphraseException e) {

               throw new SshException(e);





          context.addListeningInterface("", 4000, sshContext);


          if (log.isInfoEnabled())

     "Configuration complete.");




Within the configure method we first create a SshContext and the load a number of host keys into the configuration. Here we are loading a 2048 bit ssh-rsa key, 1024 bit ssh-dss key* and all the available sizes of a ecdsa key.

It is advisable to support as many host key types as possible so that you maintain the maximum compatibility with incoming clients.  

Next we set the software, version, comments field. This is used as part of the initial negotiation and identifies your server implementation. Use something clear and concise so that other vendors can determine the type of SSH server.

Finally in our example we add the SshContext to the Daemon using the addListeningInterface method. Here we tie the configuration to an IP/Port. You can use the same SshContext across multiple listening interfaces if required.


Starting the Server


To start the server create your main method ensuring you add your license code where indicated before calling the API.

public static void main(String[] args) throws Exception {





          // END OF LICENSE CODE

          ExampleSSHD sshd = new ExampleSSHD();




The startup method starts the server. Before we can run this however we need to extend our configure method to support the various authentication, session and file systems you want to provide to incoming SSH clients.

Authentication Providers

Installing a File System for SFTP

Supporting SCP


* Depending on the installed JCE you may be restricted to creating only 1024 bit keys. If you require higher ssh-dss key sizes generate them externally and load them as above. We support reading and using larger key sizes, unfortunately the JCE restriction prevents us from generating them.