Created
January 16, 2017 12:50
-
-
Save soxofaan/dffad18f79c03ed2df3b8e090fb666ee to your computer and use it in GitHub Desktop.
Script to fix SSH agent environment variables on a remote server after reconnecting to a screen session
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 | |
# Script to fix the SSH agent environment variable after reconnecting to a running screen session. | |
# Usage: *source* this script (don't just execute). | |
# For example, if you store it at ~/screen-ssh-agent-fix.sh, create this alias to have it available easily: | |
# alias screenfix='source ~/screen-ssh-agent-fix.sh' | |
echo "Updating ssh-agent socket environment.." | |
echo "Current value: $SSH_AUTH_SOCK" | |
export SSH_AUTH_SOCK=$(find /tmp/ssh-* -user `whoami` -name agent\* -printf '%T@ %p\n' 2>/dev/null | sort -k 1nr | sed 's/^[^ ]* //' | head -n 1) | |
if [ $? -gt 0 ]; then | |
echo "ERROR!" | |
exit $? | |
fi | |
echo "New value: $SSH_AUTH_SOCK" | |
echo "All done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment