Last active
September 30, 2020 13:50
-
-
Save mgwilliams/4d929e10024912670152 to your computer and use it in GitHub Desktop.
example of how to forward ssh-agent into an lxc
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
#!/bin/bash | |
# Example Script to forward ssh-agent socket into an unprivileged lxc | |
# This allows access to the ssh-agent by commands executed with lxc-attach | |
set -m | |
CONTAINER=$1 # e.g., test-container | |
REMOTE=$2 # e.g, [email protected] | |
bash -c " | |
trap '{ kill 0; exit; kill 0; }' SIGINT; | |
lxc-usernsexec rm .local/share/lxc/$CONTAINER/rootfs/tmp/ssh-agent-sock; | |
while true; | |
do socat UNIX:$SSH_AUTH_SOCK EXEC:'lxc-usernsexec socat STDIN UNIX-LISTEN\:.local/share/lxc/$CONTAINER/rootfs/tmp/ssh-agent-sock' | |
done | |
" & | |
pid=$! | |
# do your stuff here | |
lxc-attach -v SSH_AUTH_SOCK=/tmp/ssh-agent-sock -n $CONTAINER -- ssh $REMOTE | |
# clean up when done | |
kill -sigint -$pid |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment