Home > database >  SSH key in dockerfile invalid format
SSH key in dockerfile invalid format

Time:12-08

i have this 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"]

but when i try to build it with latest docker version, i get this error:

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
[email protected]: 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 '[email protected]:byzance/tyrion-core.git' into submodule path '//tyrion-core' failed
Failed to clone 'tyrion-core'. Retry scheduled

Can anyone tell me, how should i repair this dockerfile? Thnanks!!

CodePudding user response:

Looks like you created your key in MacOS.

Linux-based systems mostly using RSA type, but MacOS's ssh-keygen generating OpenSSH ssh key by default, not RSA.

RSA key should start from -----BEGIN RSA PRIVATE KEY-----
But OpenSSH's first line is -----BEGIN OPENSSH PRIVATE KEY-----

Just create new RSA key or convert your OpenSSH key to RSA

CodePudding user response:

The number of characters per line might not be correct.

I tested with this line and it generated the correct key :

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
  • Related