SSH Agent forwarding inside docker compose container

前端 未结 2 837
青春惊慌失措
青春惊慌失措 2021-02-06 03:13

Could not open a connection to your authentication agent.

I am following the approach of mounting the $SSH_AUTH_SOCK as a volume, but doing so with compose.

相关标签:
2条回答
  • 2021-02-06 03:33

    I solved it using whilp/ssh-agent, though you should note that this is not using SSH_AUTH_SOCK directly and requires an additional long running container. I'll integrate this approach into docker-rails for ease of use.

    1. Start a long running container docker run -d --name=ssh-agent whilp/ssh-agent:latest

    2. Add your key docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/ssh -it whilp/ssh-agent:latest ssh-add /ssh/id_rsa

    3. List your keys docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/ssh -it whilp/ssh-agent:latest ssh-add -L

    4. bash into a container and check the key with ssh -T git@bitbucket.org

    My yaml looks like:

    web:
        build: .
        working_dir: /project
        ports:
          - "3000"
    
        environment:
          # make ssh keys available via ssh forwarding (see volume entry)
          - SSH_AUTH_SOCK=/ssh-agent/socket
    
        volumes_from:
          # Use configured whilp/ssh-agent long running container for keys
          - ssh-agent
    
    0 讨论(0)
  • 2021-02-06 03:48

    The previous accepted answer using whilp/ssh-agent did not work for me for some reason (it worked before but since last changes it doesn't and I don't know why) so I created my own agent container:

    docker-ssh-agent

    based on minimal alpine:3.4 base image. So anyone still having trouble with this on OSX, check the README it's now really easy to get it up and running!

    0 讨论(0)
提交回复
热议问题