Documentation
Open Source Release Policy
Export Compliance
Using BouncyCastle
Installing the API
Enabling Logging
Per-Connection Logging
Third Party Dependencies
Generating SSH Keys
Using BouncyCastle
Using SSH Public Keys in Java
Supporting ED25519/Curve25519
Supporting Compression
Integrating Licensing into Maven Builds
Creating an SSH Client
Public Key Authentication
Keyboard Interactive Authentication
Public Key Authentication with sshagent
Executing Single Commands
Executing Commands within a Shell
Transferring Files
Connecting through Proxies
Display the Authentication Banner
Using the SFTP Client
Port Forwarding
Working Examples
Configuring Listening Interfaces
Configuring Host Keys
Password Authentication
Public Key Authentication
Challenge-Response Authentication
Configuring Port Forwarding
Configuring SFTP
Supporting SCP
Implementing your own File System
Creating an Interactive Terminal
Proxy Protocol Support
Configuring Listening Interfaces
When we created our first SshServer we passed a port number through in the constructor.
SshServer server = new SshServer(2222);
Code language: JavaScript (javascript)
This will start up a listening interface on the port you provide on all interfaces. But you may want to control this more tightly. There is an option using the default constructor of SshServer to create it without defining any interfaces.
If you use the default constructor or want to add additional interfaces at any time after we have created our SshServer we can use:
server.addInterface("127.0.0.1", 10022);
Code language: CSS (css)
Or with an InetAddress directly
server.addInterface(InetAddress.getLoopbackAddress(), 10022);
Code language: CSS (css)
Every connection on the SshServer must have a SshServerContext object associated with it. SshServerContext defines the configuration of the connection such as the host keys, authenticators and its behaviour and permissions through configuration policy objects like ForwardingPolicy and FileFactory. The SshServer class manages this for you, creating a context based on the configuration options available on SshServer, like addHostKey, addAuthenticator, etc.
For more advanced users, you can provide a factory object to create a configuration context for each incoming connection yourself, overriding the managed contexts provided by SshServer. In order to do this, you will be required to set an instance of ProtocolContextFactory<SshServerContext> on an interface.
server.addInterface(InetAddress.getLoopbackAddress(), 10022, new ProtocolContextFactory<SshServerContext>() {
public SshServerContext createContext(SshEngineContext engineContext, SocketChannel socket) {
SshServerContext sshContext = new SshServerContext(engineContext.getEngine());
// Configure context adding host keys, authenticators, file factory, channel factory etc.
return sshContext;
}
});
Code language: PHP (php)
You can add as many interfaces as you need. You can also mix a combination of SshServer managed contexts or your own context factories.