I have created an Amazon Linux 2 instance where I have deployed a Java program launched with systemd. The Java program is a vertx-shell application which is using Apache Mina to start a SSH server on port 2000. It should possible to connect to the SSH server with 2 ways : public key or password auth.
After a classical ssh authentication on port 22 to access my amazon instance, I can connect to the java ssh server running on port 2000 locally with password auth. However, when I try to connect to SSH server from my local machine providing the Amazon private key, the connection is stuck on 'debug1: Local version string SSH-2.0-OpenSSH_7.5' line and finally refused after a timeout of 2 minutes :
ssh -i /Users/toto/.ssh/my_amazon_key.pem -p 2000 [email protected] -vvv
OpenSSH_7.5p1, LibreSSL 2.5.4
debug1: Reading configuration data /Users/toto/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 52: Applying options for *
debug2: resolving "my-application.server.com" port 2000
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to my-application.server.com [35.XXX.XX.XX] port 2000.
debug1: Connection established.
debug1: key_load_public: No such file or directory
debug1: identity file /Users/toto/.ssh/my_amazon_key.pem type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/toto/.ssh/my_amazon_key.pem-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.5
ssh_exchange_identification: Connection closed by remote host
On the Java application log, I can see a log of somebody trying to connect to the SSH server but failing to authenticate after 2 minutes.
Of course, I have checked in my Amazon security group that I have opened port 2000. There is no denied IP in my case.
Here is the Java code running the SSH server :
ShellService service = ShellService.create(vertx,
new ShellServiceOptions()
.setTelnetOptions(
new TelnetTermOptions().
setHost("localhost").
setPort(5000))
.setSSHOptions(
new SSHTermOptions().
setHost("0.0.0.0").
setPort(2000).
setKeyPairOptions(new JksOptions().
setPath("ssh/keystore.jks").
setPassword("wibble")).
setAuthOptions(new ShiroAuthOptions().
setConfig(new JsonObject().put("properties_path", "classpath:ssh/auth.properties"))))
);
Any idea ? Vertx/Apache Mina config ? Conflict between SSHD running on port 22 and port 2000 ?
Ok, I finally found out the problem. Actually, I had to do 2 things :