Last active
July 12, 2022 17:52
-
-
Save routevegetable/1b881bf53506316762e5b1a80848b1f1 to your computer and use it in GitHub Desktop.
ssh things
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
SOCK_LINK=/tmp/ssh_auth_sock_link | |
start_ssh_agent() { | |
eval "$(ssh-agent -s)" | |
ssh-add ~/.ssh/id_ed25519 | |
ln -vsnf $SSH_AUTH_SOCK $SOCK_LINK | |
} | |
if [[ $- == *i* ]] && ! [[ -e $SOCK_LINK ]]; then | |
# Agent socket link doesn't exist - assume agent isn't running | |
start_ssh_agent | |
fi | |
export SSH_AUTH_SOCK=$SOCK_LINK |
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
SOCK_LINK=/tmp/ssh_auth_sock_link | |
SOCK_LOCK=/tmp/sock_lock | |
if [[ $- == *i* ]] && [[ $SSH_AUTH_SOCK ]] && [[ $SSH_AUTH_SOCK != $SOCK_LINK ]]; then | |
# We have a sock | |
# Open a lock for our sock | |
exec {FD}<>$SOCK_LOCK | |
# Flock our sock lock | |
if ! flock -x -w 2 $FD; then | |
echo "Failed to flock the sock lock" | |
else | |
# Sock lock has been flocked! | |
ln -vsnf $SSH_AUTH_SOCK $SOCK_LINK | |
flock -u $FD | |
fi | |
fi | |
export SSH_AUTH_SOCK=$SOCK_LINK |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment