public
Created

Shell script to use in a vagrant provisioning script to enable SSH agent forwarding

  • Download Gist
gistfile1.sh
Shell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
#!/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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.