Linux – lazy prompt for ssh public key passphrase

arch linuxlinuxssh

I have ssh public keys set up on my computers. They have passphrases. Whenever I need to, e.g. push to github, I have to type in the passphrase. Each time. And I'd rather ssh remembered on subsequent accesses.

ssh-agent/keychain seem to just about fit the bill, except they bother me for the passphrase when I log in (when I might not be sure I need to use my ssh keys), not when I'm trying to use ssh.

Is there some feature in either of those tools or some other tool that would remember the ssh passphrase, but maybe grab it when I type it in for ssh instead of when the session opens?

I somehow got this working on a Fedora 16 box a while ago, but can't remember what I did.

Best Answer

Here's what I used to solve this problem for ssh shells. I alias the ssh command to first check if the keys have been loaded and if not, load them first, then perform the ssh command:

alias ssh='[[ `ssh-add -l` == "The agent has no identities." ]] && ssh-add; ssh'

I put that in my .alias and source it from .bashrc

Related Question