Skip to content

Latest commit

 

History

History

ssh-server-demo

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Java SSH server + client library and examples

Simple ssh server and client with examples how to use it. Implementation uses Apache Mina project. Server supports following clients:

  • ssh terminals - like putty or 'OpenSSH SSH client', providing REPL interface.
  • ssh commands - single commands send using 'OpenSSH SSH client'
  • java client - 'ssh-java' client library for connection from java runtime

Supported use cases

Components

  • ssh-server - versatile library for embedding ssh server into Java applications.
  • ssh-client - versatile library for embedding ssh client into Java applications.
  • ssh-examples - examples of use for ssh-server and ssh-client.

Using ssh-server

  • use dependencies
    <dependency>
      <groupId>itx.ssh.server</groupId>
      <artifactId>ssh-server</artifactId>
      <version>1.0.0</version>
    </dependency>
    
    compile 'itx.ssh.server:ssh-server:1.0.0'
    
  • start server
  • override CommandProcessors

Using ssh-client

  • use dependencies
    <dependency>
      <groupId>itx.ssh.client</groupId>
      <artifactId>ssh-client</artifactId>
      <version>1.0.0</version>
    </dependency>
    
    compile 'itx.ssh.client:ssh-client:1.0.0'
    
  • start client
  • send and receive messages

Compile and Run tests

This command will compile project, run the tests, localy publish maven artifacts and create ssh-examples distribution.

gradle clean build publishToMavenLocal installDist distZip

After build is done, server can be started from commandline, listening on port 2222.

./ssh-examples/build/install/ssh-examples/bin/ssh-examples

1. connect to running server

In this mode, ssh client connects to running server and gets REPL interface. Example application implements supported commands for reference.

ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null user@localhost -p 2222
ssh user@localhost -p 2222

After client is connected, it may send supported commands via terminal. 'exit' command closes the session.

2. send single command to runing server

In this mode, ssh client will send separate commands to running server. Example application implements supported commands for reference.

sshpass -p secret ssh user@localhost -p 2222 "set 22"
sshpass -p secret ssh user@localhost -p 2222 "get"

3. use ssh-client to interconnect 2 JVMs over ssh

In this mode, ssh-client library may be used to conect to runnig instance of ssh-server.

supported commands

  • get - will get internal state
  • set <value> - will set internal state to given value