Created
July 21, 2019 10:52
-
-
Save shelooks16/03f6cfd4b86e1be14b83fc8f95e2e72e to your computer and use it in GitHub Desktop.
SSH agent management for windows
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
function addkey() { | |
# path to agent file with env vars | |
env=~/.ssh/agent.env | |
# path to RSA private key | |
key=~/id_rsa | |
agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } | |
agent_start () { (umask 077; ssh-agent >| "$env") && . "$env" >| /dev/null ; } | |
# ssh-add return value: 0=running w/ key; 1=running w/o key; 2=not running | |
agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) | |
agent_load_env | |
if [ -z "$SSH_AUTH_SOCK" ] || [ "$agent_run_state" = "2" ]; then | |
agent_start | |
ssh-add $key | |
echo -e "Hi, put your name here :)" | |
elif [ "$SSH_AUTH_SOCK" ] && [ "$agent_run_state" = "1" ]; then | |
ssh-add $key | |
echo -e "Running without key..." | |
elif [ "$SSH_AUTH_SOCK" ] && [ "$agent_run_state" = "0" ]; then | |
echo -e "SSH agent is already running." | |
fi | |
unset env | |
} | |
function offkey() { | |
if [ "${SSH_AGENT_PID+1}" == "1" ]; then | |
ssh-add -D | |
ssh-agent -k > /dev/null 2>&1 | |
unset SSH_AGENT_PID | |
unset SSH_AUTH_SOCK | |
else | |
echo "There is no ssh agent running." | |
fi | |
} | |
function viewkey() { | |
ssh-add -L | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment