当前位置: 首页 > 知识库问答 >
问题:

dockerfile格式中的SSH密钥无效

姜胤
2023-03-14

我有一个dockerfile:

FROM openjdk:11

COPY . .

RUN apt-get update -y
RUN apt-get install -y python

RUN mkdir -p /root/.ssh && \
    chmod 0700 /root/.ssh && \
    ssh-keyscan gitlab.com > /root/.ssh/known_hosts

ARG SSH_KEY=autofilled

RUN echo $SSH_KEY | python -c "key = raw_input();print \"-----BEGIN OPENSSH PRIVATE KEY-----\" + \"\\n\" + \"\\n\".join(key[i:i+64] for i in range(0, len(key), 64)) + \"\\n\" + \"-----END OPENSSH PRIVATE KEY-----\"" > /root/.ssh/id_rsa

RUN chmod 600 /root/.ssh/id_rsa
RUN git submodule init
RUN git submodule update
RUN chmod -R +x ./sbt-dist
RUN chmod +x ./sbt
RUN ./sbt dist
WORKDIR ./target/universal
RUN unzip ./dist.zip
WORKDIR ./dist/bin
RUN chmod +x ./smart-flats
EXPOSE 5000
CMD ["./smart-flats", "-Dhttp.port=5000", "-J-Xmx1536m"]

但当我尝试用最新的docker版本构建它时,我得到了以下错误:

Step 10/19 : RUN git submodule update
 ---> Running in dac2651ed54a
Cloning into '//tyrion-core'...
Warning: Permanently added the ECDSA host key for IP address '172.65.251.78' to the list of known hosts.
Load key "/root/.ssh/id_rsa": invalid format
git@gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
fatal: clone of 'git@gitlab.com:byzance/tyrion-core.git' into submodule path '//tyrion-core' failed
Failed to clone 'tyrion-core'. Retry scheduled

谁能告诉我,我应该如何修复这个dockerfile?谢谢!!

共有2个答案

公羊学义
2023-03-14

每行的字符数可能不正确。

我用这行代码进行了测试,它生成了正确的密钥:

echo $SSH_KEY | python -c "key = raw_input();print \"-----BEGIN OPENSSH PRIVATE KEY-----\n\" + \"\\n\".join(key[i:i+70] for i in range(0, len(key), 71)) + \"\n-----END OPENSSH PRIVATE KEY-----\""  > /root/.ssh/id_rsa
姜俊逸
2023-03-14

看起来你在MacOS中创建了密钥。

基于Linux的系统大多使用RSA类型,但是MacOS的ssh-keygen默认情况下生成OpenSSHssh key,而不是RSA

RSA密钥应该从----开始RSA私钥------
但是OpenSSH的第一行是----开始OpenSSH私钥------

只需创建新的RSA密钥或将OpenSSH密钥转换为RSA即可

 类似资料:
  • 11:12:17,289信息[org.apache.Coyote.http11.http11protocol](MSC服务线程1-2)JBWeb003001:Coyote http/1.1正在初始化:http-/0.0.0.0:8080 11:12:17,297信息[org.apache.Coyote.http11.http11protocol](MSC服务线程1-2)JBWeb003000:Co

  • 我试图克隆一个回购,其中有子模块。主回购是克隆罚款,但当我做在dockerfile子模块抛出和错误。 在图像中我有这个 我无法控制子模块。我不确定是否可以从到https以获取子模块。 我甚至尝试使用route 下面是构建命令的一部分。 请帮帮忙。这很令人沮丧(

  • 我使用的是ruby EC2 SDK,版本2。用EC2生成的密钥的私钥材料存储在字符串中。我正在尝试使用生成将密钥导入EC2所需的公钥材料 我尝试了一些新的东西。我使用EC2 web控制台从头开始生成了一个新密钥,然后按照Raphael在下面指出的方法生成了一个公共密钥 密钥未加密。 在尝试通过web控制台或代码导入公钥时,我得到了同样的错误。 而第一个生成的文件以 现在的问题是如何在Ruby中生成

  • 我正在使用GitLab为我的django项目构建CI/CD。作为我部署阶段的一部分,我有 构建在ssh add ~/处崩溃。ssh/id\u rsa

  • 有什么建议吗?我试图用puttygen转换我的钥匙,但仍然不起作用!我的pub密钥的开头是ssh rsa密钥。。私钥:--开始OPENSSH私钥--。。键--结束OPENSSH私钥--

  • 问题内容: 我正在使用SSLServerSocket和java.ssl包中的其他类在Java中测试SSL。运行以下代码时,出现异常java.io.IOException:无效的密钥库格式。我的代码: 文件key.txt:1268312345812304612348712634283427346我想我应该在key.txt文件中放一些东西,但是我不知道要放什么。可能是经过消毒的物体。 编辑:客户端代码