Created
April 26, 2013 00:04
-
-
Save bendavis78/5464209 to your computer and use it in GitHub Desktop.
Shell script to use in a vagrant provisioning script to enable SSH agent forwarding
This file contains hidden or 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 | |
echo "Setting up agent forwarding..." | |
mkdir -p /root/.ssh | |
chmod 0700 /root/.ssh | |
echo "Host *\n StrictHostKeyChecking no" >> /root/.ssh/config | |
chmod 0600 /root/.ssh/config | |
ppid=$PPID | |
found_auth_sock="" | |
while [[ $SSH_AUTH_SOCK == "" && $ppid != "1" ]]; do | |
f=`ls /tmp/ssh*/agent.$ppid 2>/dev/null` | |
if [[ -z "$f" ]]; then | |
ppid=`cat /proc/$ppid/status | grep PPid | awk '{print $2}'` | |
else | |
export SSH_AUTH_SOCK="$f" | |
echo "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" | |
fi | |
done | |
if [[ -z "$SSH_AUTH_SOCK" ]]; then | |
echo "Could not find running ssh agent.\n" 1>&2 | |
exit 1 | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment