-
-
Save gubatron/2f457d4d7cc2b21272824a7805382cdb to your computer and use it in GitHub Desktop.
startSSHAgent() { | |
if [[ -z "$SSH_AGENT_PID" ]]; then | |
if [[ $(pgrep ssh-agent) ]]; then | |
export SSH_AGENT_PID=$(pgrep ssh-agent) | |
echo "Found existing ssh-agent PID, SSH_AGENT_PID=${SSH_AGENT_PID}" | |
else | |
echo "Starting fresh ssh agent" | |
eval `ssh-agent` | |
fi | |
fi | |
ssh-add ~/.ssh/my-private-key1 | |
ssh-add ~/.ssh/my-private-key2 | |
#... | |
ssh-add ~/.ssh/my-private-keyN | |
kill_old_ssh_agents #see https://gist.github.com/gubatron/2d97b31b0621c459f8b5ee8665c9f7b9 | |
} |
hey @zander long time no see :)
is the umask 077
to verify that the current user has proper permissions to execute ssh-agent? (and not the world/group)
or that the ssh-agent process doesn't give permissions to others but the user launching it?
today I also learned about that -t <life>
parameter, has there ever been a case in which you thought necessary to keep your sessions only 48 hours long? I can keep a terminal window open for a week easily
This approach of writing the ssh-agent output to a file > $HOME/.ssh/agent
is also interesting. I just eval
the output
Hi guba! Miss your patches at Flowee.org :)
The umask is probably not really needed, it was to make sure that the file is only readable by owner.
the limit of 48 hours is not on the life of the agent, it is on how long the agent keeps passwords. So you'd have to do a 'ssh-add' again after that. It is purely for security.
I just eval the output
That has the downside that if you logout your ssh-agent will keep running but you can't reach it anymore. Next time you login another agent will start. And you'll end up with more and more of them.
My writing file solution also means that if I login on the desktop and then later ssh to the same machine then I can reuse the already running ssh agent.
well I only eval if I can't find an existing ssh-agent, otherwise yes you end up with a bunch of ssh-agent processes
Ill check what's up with flowee.org and how I can help once I get a breather
I have this one for some years now;