英文:
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,
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论