Reputation: 15750
Folks, After following a few threads on how to add ssh keys to the docker container for the application build phase, I am getting an interesting error:
Load key "/root/.ssh/id_rsa": invalid format
My Dockerfile:
RUN mkdir /root/.ssh/
ADD serviceBitbucketKey.ssh /root/.ssh/id_rsa
RUN chmod 400 /root/.ssh/id_rsa
RUN touch /root/.ssh/`known_hosts
RUN ssh-keyscan bitbucket.org >> /root/.ssh/known_hosts
RUN git ls-remote [email protected]:orgName/repo.git
RUN git config --global url.ssh://[email protected]/.insteadOf https://bitbucket.org/
I do know the key is fine... it was generated via
ssh-keygen -t rsa -b 4096 -f serviceBitbucketKey.ssh
Suggestions? Thanks!
Upvotes: 5
Views: 4008
Reputation: 1323065
Try, assuming, as detailed in Adiii's answer, that the permissions are OK, to generate a key using the old PEM format (instead of the new OpenSSH one):
ssh-keygen -t rsa -P "" -C "your-email-address" -m PEM
Upvotes: 2
Reputation: 59896
I thing its permission issue if the key is valid, try with this
FROM alpine:3.7
#copy key
ADD serviceBitbucketKey.ssh /root/.ssh/id_rsa
#install git
RUN apk --no-cache update git
#set proper permission
RUN chmod 600 /root/.ssh/id_rsa && \
touch /root/.ssh/known_hosts && \
ssh-keyscan bitbucket.org > ~/.ssh/known_hosts
RUN git ls-remote [email protected]:myorg/myrepo.git
Upvotes: 1