DEV Community

Discussion on: How to use SSH properly and what is SSH Agent Forwarding

Collapse
 
killrazor profile image
Tyler Christian

This doesn't address dangling agents. Each time you 'eval $(ssh-agent -s)' you are creating a new process. This will leave stranded processes that aren't cleaned up and don't die with timeouts. There is a method to reuse a PID rather than recreating each time.

Collapse
 
woodbri profile image
Stephen Woodbridge

I have this problem also. It would nice to know the correct way to handle this in .bash_login, .profile, .bashrc, .bash_logout files so if an agent already exists, it is reused, or on logout the agent is removed. I often have ssh sessions broken by connection failures so the session is not logged out.

Collapse
 
metabarj0 profile image
Sebastien Levy

Hey, if it can help, I've a repo containing a tiny script that handle that.
The way it works is pretty simple: it exposes an alias named ssh-auth that ask to authenticate the first time it is used and then re use an existing agent if invoked in a different terminal. Just, ensure to look at both .bashrc_ssh-auth.sh as well as .bashrc files : github.com/MetaBarj0/configs/tree/....
Let me know if it helps.