Code Monkey home page Code Monkey logo

docker-ssh-agent's Introduction

Docker SSH Agent

Lets you store your SSH authentication keys in a dockerized ssh-agent that can provide the SSH authentication socket for other containers. Works in OSX and Linux environments.

Why?

On OSX 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.

How to use

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:/root/.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:

With docker-compose

If you're using docker-compose this is how you forward the socket to a container:

  volumes_from:
    - ssh-agent
  environment:
    - SSH_AUTH_SOCK=/tmp/ssh-agent/socket

Without docker-compose

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=/tmp/ssh-agent/socket ubuntu:latest /bin/bash

Disable host key verification in your containers

You may wish to disable the ssh host key verification inside your containers to avoid using interactive mode at all. You can do it adding the following configuration in the /etc/ssh/ssh_config file of your containers.

Host *
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no

Deleting keys from the container

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-ssh-agent's People

Contributors

aya avatar

Watchers

 avatar  avatar

Forkers

1001pharmacies

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.