Skip to content

liip/docker-ssh-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SSH agent

SSH agent docker container image.

Environment Variables

Variable Default Value
Server
SOCKET_DIR /.ssh-agent
SSH_AUTH_SOCK /.ssh-agent/socket
SSH_AUTH_PROXY_SOCK /.ssh-agent/proxy-socket
SSH_DIR /.ssh
SSH_KEYS_DIR /.ssh-keys

Docker usage

Start the SSH container

docker run \
    -d \
    --name=sshagent \
    liip/ssh-agent:1.0.0

Add a SSH key

Replace SSH_DIR and KEY accordingly. If the key has a passphrase, you will be prompted to enter it.

SSH_DIR=~/.ssh
KEY=id_rsa
docker run \
    --rm \
    --volumes-from=sshagent \
    -v ${SSH_DIR}/${KEY}:/.ssh/${KEY} \
    -it \
    sshagent \
    ssh-key add ${KEY}

Remove a SSH key

Replace KEY accordingly.

KEY=id_rsa
docker run \
    --rm \
    --volumes-from=sshagent \
    -it \
    sshagent \
    ssh-key remove ${KEY}

Remove all SSH keys

docker run \
    --rm \
    --volumes-from=sshagent \
    -it \
    sshagent \
    ssh-key remove-all

List SSH keys

docker run \
    --rm \
    --volumes-from=sshagent \
    -it \
    sshagent \
    ssh-key list

Forward SSH Agent

docker run \
    --rm \
    --volumes-from=sshagent \
    -e SSH_AUTH_SOCK=/.ssh-agent/proxy-socket
    -it \
    <image> ssh-add -l

Docker compose usage

Start the SSH container

COMPOSE_COMPOSE_PROJECT_NAME=sshagent
version: '3.5'
services:
  agent:
    image: liip/ssh-agent:1.0.0
    restart: unless-stopped
    volumes:
      - socket_dir:/.ssh-agent
      - ssh_keys_dir:/.ssh-keys

  add:
    image: liip/ssh-agent:1.0.0
    depends_on:
      - agent
    command:
      - ssh-add
    environment:
      SSH_AUTH_SOCK: /.ssh-agent/proxy-socket
    volumes:
      - socket_dir:/.ssh-agent
      - ssh_keys_dir:/.ssh-keys

volumes:
  socket_dir:
  ssh_keys_dir:

Add a SSH key

Replace SSH_DIR and KEY accordingly. If the key has a passphrase, you will be prompted to enter it.

SSH_DIR=~/.ssh
KEY=id_rsa
docker run \
    --rm \
    --volumes-from=sshagent_agent \
    -v ${SSH_DIR}/${KEY}:/.ssh/${KEY} \
    -it \
    liip/ssh-agent:1.0.0 \
    ssh-key add ${KEY}

Remove a SSH key

Replace KEY accordingly.

KEY=id_rsa
docker run \
    --rm \
    --volumes-from=sshagent_agent \
    -it \
    liip/ssh-agent:1.0.0 \
    ssh-key remove ${KEY}

Remove all SSH keys

docker run \
    --rm \
    --volumes-from=sshagent_agent \
    -it \
    liip/ssh-agent:1.0.0 \
    ssh-key remove-all

List SSH keys

docker run \
    --rm \
    --volumes-from=sshagent_agent \
    -it \
    liip/ssh-agent:1.0.0 \
    ssh-key list

Forward SSH Agent

services:
  service_name:
    ...
    environment:
        SSH_AUTH_SOCK: /.ssh-agent/proxy-socket
    ...
    volumes:
        - ssh_agent_socket_dir:/.ssh-agent
...
volumes:
    ssh_agent_socket_dir:
        external: true

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published