ddev/ddev-ssh-agent
DDEV's ddev-ssh-agent image
1M+
originally forked from https://github.com/nardeas/docker-ssh-agent
at fb6822d0003d1c0a795e183f5d257c2540fa74a4
.
Docker container image for DDEV's ddev-ssh-agent container.
This container image is part of DDEV, and not typically used stand-alone.
Provides an ssh-agent inside the docker network.
Use DDEV
See DDEV docs
https://github.com/ddev/ddev/issues
DDEV is an open source tool for launching local web development environments in minutes. It supports PHP and Node.js.
These environments can be extended, version controlled, and shared, so you can take advantage of a Docker workflow without Docker experience or bespoke configuration. Projects can be changed, powered down, or removed as easily as they’re started.
View license information for the software contained in this image.
As with all Docker images, these likely also contain other software which may be under other licenses (such as Bash, etc from the base distribution, along with any direct or indirect dependencies of the primary software being contained).
As for any pre-built image usage, it is the image user's responsibility to ensure that any use of this image complies with any relevant licenses for all software contained within.
Lets you store your SSH authentication keys in a dockerized ssh-agent that can provide the SSH authentication socket for other containers. Works in macOS and Linux environments.
On macOS you cannot simply forward your authentication socket to a Docker container to be able to e.g clone private repositories that you have access to. You don't want to copy your private key to all containers either. The solution is to add your keys only once to a long-lived ssh-agent container that can be used by other containers and stopped when not needed anymore.
You can pull the image from DockerHub via
docker pull nardeas/ssh-agent
If you don't want to build your own images, here's a 3-step guide:
1. Run agent
docker run -d --name=ssh-agent nardeas/ssh-agent
2. Add your keys
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it nardeas/ssh-agent ssh-add /root/.ssh/id_rsa
3. Now run your actual container:
docker run -it --volumes-from=ssh-agent -e SSH_AUTH_SOCK=/.ssh-agent/socket ubuntu:latest /bin/bash
Run script
You can run the run.sh
script which will build the images for you, launch the ssh-agent and add your keys. If your keys are password protected (hopefully) you will need to input your passphrase.
Launch everything:
./run.sh
Remove your keys from ssh-agent and stop container:
./run.sh -s
0. Build
Navigate to the project directory and launch the following command to build the image:
docker build -t docker-ssh-agent:latest -f Dockerfile .
1. Run a long-lived container
docker run -d --name=ssh-agent docker-ssh-agent:latest
2. Add your ssh keys
Run a temporary container with volume mounted from host that includes your SSH keys. SSH key id_rsa will be added to ssh-agent (you can replace id_rsa with your key name):
docker run --rm --volumes-from=ssh-agent -v ~/.ssh:/.ssh -it docker-ssh-agent:latest ssh-add /root/.ssh/id_rsa
The ssh-agent container is now ready to use.
3. Add ssh-agent socket to other container
If you're using docker-compose
this is how you forward the socket to a container:
volumes_from:
- ssh-agent
environment:
- SSH_AUTH_SOCK=/.ssh-agent/socket
The above only works for root. ssh-agent socket is accessible only to the user which started this agent or for root user. So other users don't have access to /.ssh-agent/socket
. If you have another user in your container you should do the following:
socat
utility in your containersudo socat UNIX-LISTEN:~/.ssh/socket,fork UNIX-CONNECT:/.ssh-agent/socket &
sudo chown $(id -u) ~/.ssh/socket
SSH_AUTH_SOCK=~/.ssh/socket
Here's an example how to run a Ubuntu container that uses the ssh authentication socket:
docker run -it --volumes-from=ssh-agent -e SSH_AUTH_SOCK=/.ssh-agent/socket ubuntu:latest /bin/bash
Run a temporary container and delete all known keys from ssh-agent:
docker run --rm --volumes-from=ssh-agent -it docker-ssh-agent:latest ssh-add -D
docker pull ddev/ddev-ssh-agent