无法连接到Apache MINA sshd服务器

huangapple go评论60阅读模式
英文:

Unable to connect to Apache MINA sshd server

问题

我正在尝试使用Apache MINA sshd设置一个SFTP服务器。但是在尝试连接到服务器时,我收到了subsystem request failed on channel 0的错误消息。

我正在遵循这份文档。但我不确定是否漏掉了关键部分。

以下是我目前在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();
        }
    }
}

希望这能帮助你解决问题。

英文:

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();
        }
    }
}

答案1

得分: 1

我认为错误是由服务器不允许SFTP引起的。如果您查看NIMA的SFTP文档,您可以看到您可以像这样启用SFTP子系统:

SftpSubsystemFactory factory = new SftpSubsystemFactory.Builder()
    //...
    .build();
sshd.setSubsystemFactories(Collections.singletonList(factory));

为了进一步诊断问题,您可以尝试创建一个自定义的SftpEventListener并将其注册到factory.addSftpEventListener或类似的地方,

英文:

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,

huangapple
  • 本文由 发表于 2023年6月2日 03:04:08
  • 转载请务必保留本文链接:https://go.coder-hub.com/76384961.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定