0

我正在尝试借助此示例Here使用 Apache MINA SSHD 实现多用户无密码嵌入式 SFTP 。但是当我尝试连接到服务器时,它总是需要密码。

密码认证问题

SshServer sshd = SshServer.setUpDefaultServer();
        sshd.setHost("localhost");
        sshd.setPort(2222);
        sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());
        sshd.setSubsystemFactories(Collections.singletonList(new SftpSubsystemFactory()));
        sshd.setPasswordAuthenticator(
                (username, password, session) -> username.equals("test") && password.equals("password"));
        Path keys = Paths.get(".ssh/authorized_keys");
        if (keys.toFile().exists()) {
            sshd.setPublickeyAuthenticator(new AuthorizedKeysAuthenticator(keys));
            log.info("File exists....");
        }
        sshd.start();
        log.info("SFTP server started");

我已将authorized_keys(公钥文件)放在项目内的 .ssh 文件夹中。

sftp 服务器项目的 ssh 文件夹

4

0 回答 0