简体   繁体   English

ssh-添加到Docker容器中

[英]ssh-add in a docker container

I've mounted the ~/.ssh directory into my development docker container from the host machine and trying to add the deployment key to the ssh agent in the entrypoint like this: 我已经将~/.ssh目录从主机安装到开发docker容器中,并尝试将部署密钥添加到入口点中的ssh代理中,如下所示:

#!/bin/bash
set -e

#add the deployment key
if [[ ! -z ${DEPLOYMENT_SSH_KEY} ]] ; then
    echo "Adding deployment ssh key ${DEPLOYMENT_SSH_KEY} to ssh agent"
    eval $(ssh-agent -s) && ssh-add /.ssh/${DEPLOYMENT_SSH_KEY}
else
    echo "Deployment ssh key is not defined"
fi

echo "STARTING PHP FPM, CMD $@"

docker-php-entrypoint "$@"

The key gets normally added according to the logs: 通常会根据日志添加密钥:

Agent pid 8 代理pid 8

Adding deployment ssh key id_rsa to ssh agent 将部署SSH密钥ID_RSA添加到SSH代理

Identity added: /.ssh/id_rsa (rsa w/o comment) 添加身份:/。ssh / id_rsa(无注释的RSA)

However, it actually ends up with no keys added to the agent and I can't clone my repos from inside the container. 但是,它实际上最终没有向代理添加任何密钥,并且我无法从容器内部克隆我的存储库。 The command ssh-add -l executed in the container says 在容器中执行的命令ssh-add -l表示

Could not open a connection to your authentication agent. 无法打开与身份验证代理的连接。

Why's that? 为什么? I heard of the SSH agent forwarding as an alternative but I'm wondering why the method I've tried doesn't work? 我听说过SSH代理转发是一种替代方法,但我想知道为什么我尝试的方法不起作用?

Since ssh-add error message says "could not connect" it either can't find SSH_AUTH_SOCK environment variable or can't access socket path contained in that variable. 由于ssh-add错误消息显示“无法连接”,因此它要么找不到SSH_AUTH_SOCK环境变量,要么无法访问该变量中包含的套接字路径。 Since ssh-agent use /tmp for the socket by default, guess your /tmp mountpoint is broken in some way. 由于ssh-agent默认情况下将/tmp用于套接字,因此请猜测/tmp挂载点已被破坏。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM