Unable to connect to Apache MINA sshd server
I think the error is caused by the server not allowing SFTP. If you check the SFTP docs for NIMA, you can see that you can enable the SFTP subsystem like this:
SftpSubsystemFactory factory = new SftpSubsystemFactory.Builder()
    //...
    .build();
sshd.setSubsystemFactories(Collections.singletonList(factory));

For further diagnosing, you could try creating a custom SftpEventListener and registering it with factory.addSftpEventListener or similar,

I'm trying to setup a sftp server with Apache MINA sshd. But I'm getting subsystem request failed on channel 0 while trying to connect to the server.
sftp -P 22 john@localhost                                                                                                                                                            
Password authentication
(john@localhost) Password:
subsystem request failed on channel 0
Connection closed

I was following this document. But I'm not sure whether I'm missing any essential parts here.
Following is the code I'm using at the moment with mina-sshd v2.10.0.

public class Main {
    public static void main(String[] args) {

        SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setPort(22);
        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(Paths.get("hostkey.ser")));

        sshd.setShellFactory(new ProcessShellFactory("/bin/sh", "-i", "-l"));
        sshd.setCommandFactory(new ScpCommandFactory());

        sshd.setPasswordAuthenticator(new MyPasswordAuthenticator());

        try {
            System.err.println("Starting SSHD on port 22");
            sshd.start();
            Thread.sleep(Long.MAX_VALUE);
            System.err.println("Exiting after a very (very very) long time");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

