Created
January 29, 2014 23:32
-
-
Save d11wtq/8699521 to your computer and use it in GitHub Desktop.
How to SSH agent forward into a docker container
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run -rm -t -i -v $(dirname $SSH_AUTH_SOCK) -e SSH_AUTH_SOCK=$SSH_AUTH_SOCK ubuntu /bin/bash |
@benjertho After struggling for hours with the same problem (works on first shell login but after that fails), I tried a hack and it worked! Sharing here:
-
Add an entrypoint line to dockerfile
ENTRYPOINT ["/ros_entrypoint.sh"]
-
In entrypoint script, add the following at the top:
# Dynamically set SSH_AUTH_SOCK if it's available in the mounted /tmp directory
if [ -n "$(find /tmp -type s -name 'agent.*' 2>/dev/null)" ]; then
export SSH_AUTH_SOCK=$(find /tmp -type s -name 'agent.*' 2>/dev/null)
fi
- Add the following to your compose.yaml:
environment:
- SSH_AUTH_SOCK=/tmp/ssh-agent
volumes:
- /tmp:/tmp
Now the ssh auth sock will be set appropriately every time.
run docker -p 222:22 && apt install openssh-server && $(edit /etc/ssh/sshdconfig to enable root login)
on your mac of git bash
eval $(ssh-agent -s)
ssh-add
ssh -A toDockerContainer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Based on @tomdavies post, i created this Dockerfile which uses the USER statement in order to have an unpriviledged container instead of su-exec:
you run it then with