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__.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#!/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; \
}