使用ppk与sshj一起执行ssh时发生InvalidKeySpecException

时间:2018-12-13 10:53:16

标签: amazon-ec2 sshj

我正在尝试使用sshj java库将ssh转换为带有ppk文件的ec2 redhat实例,我正在获取InvalidKeySpecException。如我能够成功地将SSH转换到具有相同ppk的其他机器。 我想我在ec2实例中缺少一些配置,将不胜感激。

注意:我可以通过腻子对有问题的机器执行ssh。

下面是我在应用程序中得到的堆栈跟踪:

net.schmizz.sshj.transport.TransportException: java.security.spec.InvalidKeySpecException: key spec not recognised
        at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:33)
        at net.schmizz.sshj.transport.TransportException$1.chain(TransportException.java:27)
        at net.schmizz.concurrent.Promise.deliverError(Promise.java:95)
        at net.schmizz.concurrent.Event.deliverError(Event.java:74)
        at net.schmizz.concurrent.ErrorDeliveryUtil.alertEvents(ErrorDeliveryUtil.java:34)
        at net.schmizz.sshj.transport.KeyExchanger.notifyError(KeyExchanger.java:386)
        at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:600)
        at net.schmizz.sshj.transport.Reader.run(Reader.java:67)
Caused by: net.schmizz.sshj.common.SSHException: java.security.spec.InvalidKeySpecException: key spec not recognised
        at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:36)
        at net.schmizz.sshj.common.SSHException$1.chain(SSHException.java:29)
        at net.schmizz.sshj.transport.TransportImpl.die(TransportImpl.java:595)
        ... 1 common frames omitted
Caused by: net.schmizz.sshj.common.SSHRuntimeException: java.security.spec.InvalidKeySpecException: key spec not recognised
        at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:466)
        at net.schmizz.sshj.transport.kex.AbstractDHG.next(AbstractDHG.java:66)
        at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:358)
        at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:503)
        at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:102)
        at net.schmizz.sshj.transport.Decoder.received(Decoder.java:170)
        at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.security.GeneralSecurityException: java.security.spec.InvalidKeySpecException: key spec not recognised
        at net.schmizz.sshj.common.ECDSAVariationsAdapter.readPubKeyFromBuffer(ECDSAVariationsAdapter.java:92)
        at net.schmizz.sshj.common.KeyType$3.readPubKeyFromBuffer(KeyType.java:113)
        at net.schmizz.sshj.common.Buffer.readPublicKey(Buffer.java:464)
        ... 6 common frames omitted
Caused by: java.security.spec.InvalidKeySpecException: key spec not recognised
        at org.bouncycastle.jcajce.provider.asymmetric.util.BaseKeyFactorySpi.engineGeneratePublic(Unknown Source)
        at org.bouncycastle.jcajce.provider.asymmetric.ec.KeyFactorySpi.engineGeneratePublic(Unknown Source)
        at java.security.KeyFactory.generatePublic(KeyFactory.java:334)
        at net.schmizz.sshj.common.ECDSAVariationsAdapter.readPubKeyFromBuffer(ECDSAVariationsAdapter.java:90)
    ... 8 common frames omitted

2 个答案:

答案 0 :(得分:0)

idx = pd.PeriodIndex(['2015-01', '2015-02', '2015-03', '2015-04', '2015-05', '2015-06', '2015-07', '2015-08', '2015-09', '2015-10', '2015-11', '2015-12', '2016-01', '2016-02', '2016-03', '2016-04', '2016-05', '2016-06', '2016-07', '2016-08', '2016-09', '2016-10', '2016-11', '2016-12'], dtype='period[M]', name='DT', freq='M') mux = pd.MultiIndex.from_arrays([idx.year, idx.month], names=['year','month']) print (mux) MultiIndex(levels=[[2015, 2016], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]], labels=[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]], names=['year', 'month']) 文件是Putty私钥文件,与SSHJ支持的OpenSSH格式不兼容。您可以使用以下命令将ppk文件转换为供SSHJ使用:ppk

答案 1 :(得分:0)

这是一个非常棘手的问题,sshj库使用ssh-rsa算法。 因此,我们需要在ec2实例中添加ssh-rsa算法。 步骤:

  1. 编辑文件/ etc / ssh / sshd_config。
  2. 添加条目HostKeyAlgorithms ssh-rsa

此后开始工作。