【发布时间】:2018-05-29 13:56:17
【问题描述】:
下面基本上是 Apache MINA 服务器的代码。它工作得很好。当我连接 WinSCP 时,我被限制在目录中,无法返回,这很好。另一方面,当我连接 SSH 终端时,我可以返回和转发目录,这是我不希望发生的。
我知道这条线是限制 WinSCP 用户的原因:
sshd.setFileSystemFactory(
(FileSystemFactory) new VirtualFileSystemFactory(new File("C:/my apps").toPath()));
使用的 JAR 版本(意识到版本之间存在很大差异):
- mina-core-2.0.7
- sshd-core-1.7.0
- slf4j-api-1.7.25
- slf4j-jdk-1.7.25
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setPort(8080);
sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(new File("hostkey.ser")));
sshd.setUserAuthFactories(userAuthFactories);
sshd.setCommandFactory(new ScpCommandFactory());
sshd.setSubsystemFactories(sftpCommandFactory);
sshd.setShellFactory(new ProcessShellFactory(new String[] { "cmd" }));
// "/bin/bash", "-i", "-l"
sshd.setFileSystemFactory(
(FileSystemFactory) new VirtualFileSystemFactory(new File("C:/my apps").toPath()));
sshd.setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
if ((username.equals("username")) && (password.equals("password"))) {
return true;
}
return false;
}
});
sshd.start();
while (true);
我想知道是否有人遇到过这个问题并在 Java 中完成了它,因为我在 API 中找不到任何东西。
【问题讨论】:
标签: java windows ssh chroot mina