Skip to content

Instantly share code, notes, and snippets.

@Jell
Last active August 17, 2017 15:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jell/546244f4fcb6b4596d3f66386e0d8102 to your computer and use it in GitHub Desktop.
Save Jell/546244f4fcb6b4596d3f66386e0d8102 to your computer and use it in GitHub Desktop.
Recipe for SSH forwarding with dinghy (https://github.com/codekitchen/dinghy)
function dinghy-connect {
# Make sure SSH agent is running
ssh-add -K
# Make sure dinghy is up and running
dinghy create 2> /dev/null || echo "dinghy VM already created"
dinghy up 2> /dev/null || echo "dinghy VM already running"
# Check if SSH forwarding is already in place
DINGHY_SSH_SOCK=$(dinghy ssh find -type f /tmp/ssh-*/agent.* 2> /dev/null || echo "missing")
if [ "$DINGHY_SSH_SOCK" = "missing" ]; then
echo "starting SSH connection"
# Cleanup dangling SSH connections (just in case)
dinghy ssh 'sudo rm -rf /tmp/ssh-*'
# Run an ssh connection:
# - using an emulated terminal (-t)
# - in the background (-fn)
# - with ssh-agent forwarding (-A)
dinghy ssh -tfnA 'while true; do sleep 1000; done'
# Lookup the socket on the dinghy VM
DINGHY_SSH_SOCK=$(dinghy ssh find /tmp/ssh-*/agent.*)
else
echo "existing SSH connection"
fi
export PROXY_SSH_AUTH_SOCK=$DINGHY_SSH_SOCK
eval "$(dinghy env)"
echo "dinghy ready!"
}
version: '2'
services:
bash:
entrypoint: /bin/bash
volumes:
# SSH Forwarding (1/2)
- $PROXY_SSH_AUTH_SOCK:/ssh-agent-sock
environment:
# SSH Forwarding (2/2)
SSH_AUTH_SOCK: /ssh-agent-sock
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment