Connect to ssh-agent automatically when you login without GUI —28 March 2012
For many years now it is a commonly known good practice to use ssh public key authentication to login to remote servers, and that ssh-agent can store your passphrase so that you don’t have to enter it every time you login with your keys.
However, ssh-agent is not exactly convenient to use:
- You have to start ssh-agent and add your keys in it at some point (ideally the first time you login)
- If there is an existing ssh-agent process running you want to reuse it rather than running yet another one
If you are using a Linux desktop (with a GUI), then the above is probably easy to do, hopefully even hassle-free and automatic with a keychain tool that takes care of starting ssh-agent when you login and storing all your passphrases.
However, if you are not using a Linux desktop then your best option is to concoct some home-brew hack that you add to your
~/.bash_profile to make it automatic every time you log in. Here’s my own concoction that has evolved over the years into something readable, kept up to date on my wiki: