Skip to content

Instantly share code, notes, and snippets.

@sjmcgrath
Created April 27, 2017 20:45
Show Gist options
  • Save sjmcgrath/715caf5832d4d147274e5f53e4a8f46d to your computer and use it in GitHub Desktop.
Save sjmcgrath/715caf5832d4d147274e5f53e4a8f46d to your computer and use it in GitHub Desktop.
Save your ssh-agent environment to a temp file so you can reload it in screen sessions/etc. that have the environment from a previous ssh session.
#!/bin/bash
SSH_AGENT_FIX_ENV_FILE="${SSH_AGENT_FIX_ENV_FILE:=$HOME/tmp/ssh-agent-env}"
SSH_AGENT_FIX_ENV_DIR=$( dirname ${SSH_AGENT_FIX_ENV_FILE} )
[[ -d ${SSH_AGENT_FIX_ENV_DIR} ]] || {
mkdir -p $SSH_AGENT_FIX_ENV_DIR
}
env \
| grep SSH \
| sed "s/=/='/; s/$/'/" \
| tee $SSH_AGENT_FIX_ENV_FILE \
| sed "s/=.*//; s/^/export /" \
>> $SSH_AGENT_FIX_ENV_FILE
echo To set the SSH agent environment correctly, run the following in your screen session.
echo . "$SSH_AGENT_FIX_ENV_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment