SSH Agent forwarding inside docker compose container

前端 未结 2 845
青春惊慌失措
青春惊慌失措 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
    

提交回复
热议问题