简体   繁体   English

将ssh私钥添加到docker

[英]Adding private ssh key to docker

I am trying to add my ssh private key to docker, my Dockerfile is as follows: 我正在尝试将ssh私钥添加到docker,我的Dockerfile如下:

ARG key
RUN echo $key > panaxea-key

RUN chmod 600 panaxea-key
RUN eval $(ssh-agent -s) && ssh-add panaxea-key

Console output: 控制台输出:

Step 10/14 : RUN echo $key > panaxea-key
 ---> Using cache
 ---> 8ee023dba45e
Step 11/14 : RUN chmod 600 panaxea-key
 ---> Using cache
 ---> b7c42a9c5268
Step 12/14 : RUN eval $(ssh-agent -s) && ssh-add panaxea-key
 ---> Running in 9895e087cea5
Agent pid 9
Enter passphrase for panaxea-key: The command '/bin/sh -c eval $(ssh-agent -s) && ssh-add panaxea-key' returned a non-zero code: 1
dario@dario-X750JB:~/Panaxea_Docker$ 

Any advice? 有什么建议吗? My key doesn't have a passphrase 我的钥匙没有密码

If your key doesn't have a passphrase and ssh-add is asking you for one, it means ssh-add could not understand your key file. 如果您的密钥没有密码,并且ssh-add要求您输入密码,则意味着ssh-add无法理解您的密钥文件。 The culprit is echo $key > panaxea-key . 罪魁祸首是echo $key > panaxea-key You'll see that the file is a single line of text now and all the newlines have disappeared. 您会看到文件现在是一行文本,所有换行符都消失了。

Use echo "$key" > panaxea-key instead. 使用echo "$key" > panaxea-key代替。

This should get it to work, but the warnings about embedding a private key inside a docker image still stand. 这应该可以使其正常工作,但是关于在Docker映像中嵌入私钥的警告仍然存在。 How you get around that depends on exactly what you're trying to accomplish, but I feel like that's a different question altogether. 如何解决问题取决于您要完成的工作,但是我觉得这完全是一个不同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将私有 SSH 密钥挂载到 Docker for Windows 容器? - How to mount private SSH key to Docker for Windows container? 在构建Docker镜像时无法使用私钥进行SSH - Cannot SSH using private key while building Docker image 使用 docker 设置 ftp.ssh 目录,其中包含公钥/私钥信息 - setup ftp .ssh directory with public/private key info with docker 在docker文件中将私钥添加到ssh-agent - Add private key to ssh-agent in docker file 无法通过 ssh 将私钥添加到 docker build - Can not ssh-add private key to docker build 在 docker 中使用 -H 选项时指定 ssh 私钥文件 - specify the ssh private key file when using the -H option in docker docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" 返回空 - docker build --build-arg SSH_PRIVATE_KEY="$(cat ~/.ssh/id_rsa)" returning empty 如何在我的 docker 容器启动时设置我的私有 ssh_key 的正确权限? - How to set the right permissions of my private ssh_key on start of my docker container? 我可以授予 docker 容器 ssh 访问主机的权限而不同时授予其私钥吗? - Can I give a docker container ssh access to a host without also giving it the private key? Docker:一个或多个构建参数 [SSH_PRIVATE_KEY] 没有被消耗(但它应该有) - Docker: One or more build-args [SSH_PRIVATE_KEY] were not consumed (but it should have)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM