【问题标题】:Apache Mina restricting a user through SSH on Windows serverApache Mina 通过 Windows 服务器上的 SSH 限制用户
【发布时间】: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


    【解决方案1】:

    您也必须在 shell 中为 chroot 用户实现一个全新的 shell(在您的情况下是 cmd 的替代品)。这几乎是不可能的。

    在 *nix 系统上有现成的 chrooting shell 工具。但是您的服务器似乎在 Windows 上运行 (cmd)。我认为在 Windows 上没有任何 chrooting 工具。我什至无法想象这是可能的。

    但是您为什么不只是设置用户权限,以允许登录用户仅漫游到您希望他/她进入的文件夹?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-09-02
      • 1970-01-01
      • 1970-01-01
      • 2019-03-18
      • 1970-01-01
      • 2012-11-03
      • 1970-01-01
      相关资源
      最近更新 更多