“找不到匹配的主机密钥类型” - Apache MINA SFTP服务器

时间:2015-11-13 10:32:26

标签: java apache mina sshd

我希望使用Apache MINA在Java中设置SFTP服务器。

似乎启动正常,但当我尝试使用OpenSSH客户端连接到它时,我得到:

$ ssh localhost -p 2222
Unable to negotiate with ::1: no matching host key type found. Their offer: ssh-dss
$ ssh -V
OpenSSH_7.1p1, OpenSSL 1.0.2d 9 Jul 2015

Java应用程序日志:

! java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms (client: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa / server: ssh-dss)
! at org.apache.sshd.common.session.AbstractSession.negotiate(AbstractSession.java:1279) ~[sshd-core-1.0.0.jar:1.0.0]

我的Maven依赖项是:

<dependency>
    <groupId>org.apache.sshd</groupId>
    <artifactId>sshd-sftp</artifactId>
    <version>0.11.0</version>
</dependency>

<dependency>
    <groupId>org.apache.sshd</groupId>
    <artifactId>sshd-core</artifactId>
    <version>1.0.0</version>
</dependency>

我的应用启动代码看起来像(从https://stackoverflow.com/a/8974515/8261复制)

import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.UserAuth;
import org.apache.sshd.server.auth.UserAuthNoneFactory;
import org.apache.sshd.server.command.ScpCommandFactory;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
import org.apache.sshd.sftp.subsystem.SftpSubsystem;

private void startSftpServer() throws IOException {
    SshServer sshd = SshServer.setUpDefaultServer();
    sshd.setPort(2222);
    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(
            new File("hostkey.ser")));

    List<NamedFactory<UserAuth>> userAuthFactories = new ArrayList<NamedFactory<UserAuth>>();
    userAuthFactories.add(new UserAuthNoneFactory());
    sshd.setUserAuthFactories(userAuthFactories);

    sshd.setCommandFactory(new ScpCommandFactory());

    List<NamedFactory<Command>> namedFactoryList = new ArrayList<NamedFactory<Command>>();
    namedFactoryList.add(new SftpSubsystem.Factory());
    sshd.setSubsystemFactories(namedFactoryList);

    sshd.start();
}

如何向服务器添加更多现代主机密钥算法?

2 个答案:

答案 0 :(得分:12)

这对我有用:

更改Maven pom.xml以删除&#34; sshd-sftp&#34;,它现在是&#34; sshd-core&#34;的一部分:

<dependency>
    <groupId>org.apache.sshd</groupId>
    <artifactId>sshd-core</artifactId>
    <version>1.0.0</version>
</dependency>

添加到&#34; startSftpServer&#34;:

    AbstractGeneratorHostKeyProvider hostKeyProvider =
            new SimpleGeneratorHostKeyProvider(SERVER_KEY_FILE.toPath());

    hostKeyProvider.setAlgorithm("RSA");
    sshd.setKeyPairProvider(hostKeyProvider);

...使用这个库似乎有很多猜测,这似乎是一个安全&#34;库。

答案 1 :(得分:0)

我遇到了同样的问题,并通过“ setAlgorithm(KeyUtils.RSA_ALGORITHM)”解决了,但是我 还有另一个问题,我的应用无法将mina shhd的日志输出为您的日志:

! java.lang.IllegalStateException: Unable to negotiate key exchange for server host key algorithms (client: ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519-cert-v01@openssh.com,ssh-rsa-cert-v01@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-ed25519,ssh-rsa / server: ssh-dss)

!在org.apache.sshd.common.session.AbstractSession.negotiate(AbstractSession.java:1279)〜[sshd-core-1.0.0.jar:1.0.0]

您如何配置使mina shhd输出的日志配置,我是mina shhd的新手,如果我可以看到mina shhd的日志,将非常有帮助。