
Setting up keychain for bash on a linux server
Because it's nice to not enter your SSH passwords everytime you log on.
I have managed to do much messing around with linux recently:
I’m a big fan of using ssh keys, and have powershell setup to request my password once. However on the linux server I had the following in my .profile:
if [ -z "$SSH_AUTH_SOCK" ] ; then eval `ssh-agent -s` ssh-add fi
Which is fine, but it starts an ssh-agent instance for every log-in. And this means that I’m prompted for the password everytime I log in.
One answer I’ve seen frequently is to use keychain, and I have installed it in the past:
sudo apt-get update sudo apt-get install keychain
But, I failed (yes, I know, I suck…) and couldn’t get it to work… But today I finally invested some proper time into understanding ssh-agent, keychain and bash. Thanks to ZIADI Mohamed ali’s answer on serverfault I’ve now got it working nicely. In my .profile I now have this line:
eval `keychain ~/.ssh/id_rsa --eval`
And I’m only asked for the password once. Job’s a good ‘un!