使用openssl将SSH2 RSA私钥转换为.pem

时间:2016-01-04 04:35:36

标签: unix ssh openssl rsa pem

我正在尝试使用Ganymed API连接到远程服务器。

FROM centos:centos6

RUN set -x             && \
    yum install -y tar && \
    yum clean all

RUN set -x       && \
    curl -sOL 'http://download.oracle.com/otn-pub/java/jdk/7u51-b13/jdk-7u51-linux-x64.rpm' \
         -H 'Cookie: oraclelicense=accept-securebackup-cookie' && \
    rpm -i jdk-7u51-linux-x64.rpm && \
    rm jdk-7u51-linux-x64.rpm && \
    echo 'export JAVA_HOME=/usr/java/jdk1.7.0_51/' >> ~/.bashrc

ENV HBASE_VERSION 0.94.24
RUN set -x         && \
    curl -L http://archive.apache.org/dist/hbase/hbase-$HBASE_VERSION/hbase-$HBASE_VERSION.tar.gz | \
    tar zvx --null && \
    echo "export HBASE_HOME=/hbase-$HBASE_VERSION" >> ~/.bashrc

ADD hbase-site.xml /hbase-$HBASE_VERSION/conf/hbase-site.xml
ADD run.sh /hbase-$HBASE_VERSION/bin/LOCAL-run.sh

ENV PHOENIX_VERSION 3.2.0
RUN set -x && \
    curl -L http://archive.apache.org/dist/phoenix/phoenix-$PHOENIX_VERSION/bin/phoenix-$PHOENIX_VERSION-bin.tar.gz | \
    tar zvx --null && \
    cp /phoenix-$PHOENIX_VERSION-bin/common/phoenix-core-$PHOENIX_VERSION.jar /hbase-$HBASE_VERSION/lib/


CMD ["/hbase-0.94.24/bin/LOCAL-run.sh"]

当我运行上面的代码时,我得到以下异常。

String SFTPHOST = "10.91.35.169";
String SFTPUSER = "amxadmin";
int SFTPPORT = 60022;
File keyfile = new File("/home/jbadmin/.ssh2/id_rsa_2048_a"); 
String keyfilePass = null; // will be ignored if not needed
Connection conn = new Connection(SFTPHOST);
conn.connect();

conn.authenticateWithPublicKey(SFTPUSER, keyfile, keyfilePass);

仔细阅读api文档后,我才知道允许的密钥格式为java.io.IOException: Publickey authentication failed. at ch.ethz.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:331) at ch.ethz.ssh2.Connection.authenticateWithPublicKey(Connection.java:499) at ch.ethz.ssh2.Connection.authenticateWithPublicKey(Connection.java:546) Caused by: java.io.IOException: Invalid PEM structure, '-----BEGIN...' missing at ch.ethz.ssh2.crypto.PEMDecoder.parsePEM(PEMDecoder.java:141) at ch.ethz.ssh2.crypto.PEMDecoder.decode(PEMDecoder.java:321) at ch.ethz.ssh2.auth.AuthenticationManager.authenticatePublicKey(AuthenticationManager.java:240)

当我尝试将基于.pem格式的私钥转换为SSH2 RSA格式时,使用openssl我收到以下错误。

.pem

我的私钥:

[jbadmin@xxxxxxx .ssh2]$ openssl req -x509 -key /home/jbadmin/.ssh2/id_rsa_2048_a -nodes -days 365 -newkey rsa:2048 -out id_rsa_2048_a.pem
unable to load Private Key
139994671441736:error:0906D06C:PEM routines:PEM_read_bio:no start line:pem_lib.c:703:Expecting: ANY PRIVATE KEY

如果有其他方法可以使用opensslssh-keygen-g3

建议我

0 个答案:

没有答案