gpt4 book ai didi

git - Docker 加载 key "/root/.ssh/id_rsa": invalid format

转载 作者:行者123 更新时间:2023-12-02 13:46:31 25 4
gpt4 key购买 nike

我正在尝试克隆其中包含子模块的存储库。主仓库可以很好地克隆,但是当我这样做时 git submodule update --init --recursive在 dockerfile 子模块抛出和错误。

fatal: clone of 'git@github.com:jkeys089/lua-resty-hmac.git' into submodule path '/tmp/third-party/lua-resty-hmac' failed
Failed to clone 'third-party/lua-resty-hmac'. Retry scheduled
Cloning into '/tmp/third-party/lua-resty-jwt'...
load pubkey "/root/.ssh/id_rsa": invalid format
Warning: Permanently added the RSA host key for IP address '140.82.118.3' to the list of known hosts.
Load key "/root/.ssh/id_rsa": invalid format
git@github.com: Permission denied (publickey).

在图像中我有这个
# authorise ssh host
RUN mkdir /root/.ssh/ \
&& chmod 700 /root/.ssh \
&& ssh-keyscan github.com > /root/.ssh/known_hosts

# add key and set permission
RUN echo "${SSH_PRIVATE_KEY}" >> /root/.ssh/id_rsa \
&& echo "$ssh_pub_key" > /root/.ssh/id_rsa.pub \
&& chmod 600 /root/.ssh/id_rsa.pub \
&& chmod 600 /root/.ssh/id_rsa

我无法控制子模块。我不确定是否可以从 git@github.com 更改到 https 来获取子模块。

我什至尝试使用 GITHUB_TOKEN路线
# start up git and clone
RUN git config --global url."https://${GITHUB_TOKEN}@github.com/".insteadOf "https://github.com/" \
&& git clone https://github.com/GluuFederation/gluu-gateway.git /tmp \
&& cd /tmp/ \
&& git submodule update --init --recursive

下面是构建命令的一部分。 build --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" --build-arg ssh_pub_key="$(cat ~/.ssh/id_rsa.pub)"
请帮忙解决这个问题。这非常令人沮丧。 :(

最佳答案

另一个可能的问题是,如果您使用 Makefile 来运行 docker build 命令。在这种情况下,Makefile 中的命令将类似于:

docker-build:
docker build --build-arg SSH_PRIVATE_KEY="$(shell cat ~/.ssh/id_rsa)"
Make不幸的是用空格替换换行符( make shell)
这意味着写入容器的 ssh key 具有不同的格式,从而产生上述错误。
我无法找到在 Makefile 命令中保留换行符的方法,因此我采用了一种解决方法,将 .ssh 目录复制到 docker build 上下文中,通过 Dockerfile 复制文件,然后将其删除。

关于git - Docker 加载 key "/root/.ssh/id_rsa": invalid format,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59509976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com