Christoph Polcin

Start SSH-Agent Shell Script

a very simple keychain re­place­ment script to manage your SSH and GPG keys.

Replace __USER__and __KEYS__.

#!/bin/sh
# www.christoph-polcin.com

# absolute path to your private keys dir
SSH_KEY_HOME="/home/__USER__/.ssh"
# private keys, space separated
SSH_KEYS="__KEYS__"

AGENT_FILE="${SSH_KEY_HOME}/.ssh-agent.sh"

[[ -e "$AGENT_FILE" ]] && eval `cat "$AGENT_FILE"`
[[ -z $SSH_AGENT_PID || \
    "$(ps x | grep "ssh-agent" | grep -c $SSH_AGENT_PID)" -lt '1' ]] \
&& { \
    ssh-agent -s > "$AGENT_FILE"; \
    eval `cat "$AGENT_FILE"`; \
    for key in $SSH_KEYS; do ssh-add "${SSH_KEY_HOME}/${key}"; done; \
}