我正在尝试使用 Apache MINA sshd 设置 sftp 服务器。但我在尝试连接到服务器时遇到
subsystem request failed on channel 0
。
sftp -P 22 john@localhost
Password authentication
(john@localhost) Password:
subsystem request failed on channel 0
Connection closed
我正在关注此文档。但我不确定这里是否遗漏了任何重要的部分。
以下是我目前在 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();
}
}
}
我认为该错误是由于服务器不允许SFTP引起的。如果您检查 NIMA 的 SFTP 文档,您可以看到可以像这样启用 SFTP 子系统:
SftpSubsystemFactory factory = new SftpSubsystemFactory.Builder()
//...
.build();
sshd.setSubsystemFactories(Collections.singletonList(factory));
为了进一步诊断,您可以尝试创建自定义
SftpEventListener
并将其注册为 factory.addSftpEventListener
或类似的,
现在如何工作,我取下了最新版本 2.12.1,但 SftpSubsystemFactory 工厂似乎不存在?