I have (and need) multiple ssh keys. I often need all of them in a session and I configure ssh so that it automatically selects the right one for the right server, so I thought I would write a script which adds them all on login. I put this in .profile:

eval $(ssh-agent)
ssh-add ~/list/of/ ~/paths/to/keys

That works fine, in that it attempts to add the keys on login and asks me for the passwords using ssh-askpass (note lowercase: I mean the program, not the environment variable).

However, I also use pass to store my passwords, including those for my various ssh keys. I know the password for pass's gpg authentication, but of course I don't memorise all of the passwords stored in pass, which makes the ssh prompt for those passwords useless.

How can I have ssh-add ask pass for the passwords for the different passwords (and then have pass prompt me for the gpg authenication password, rather than ssh prompt me for separate ssh passwords)?

The passwords in pass are not named the same as the ssh id files, but are named in a pattern-similar way (e.g for an ssh id id_rsa_personal the corresponding password would be (~/.password-store/)ssh/personal).

Perhaps a raw gpg script bypassing the pass wrapper entirely would be better?

All help appreciated!

1 Answer 1


This works for me:

if [[ -v PASS_PATH ]]; then
    pass $PASS_PATH
    exit $?

for I in \
    "$HOME/.ssh/id_key_1_ed25519;your/path/in/pass/for/key1" \
    SSH_ASKPASS_REQUIRE="force" SSH_ASKPASS="$0" PASS_PATH="$PASS" ssh-add $SSHKEYPATH < /dev/null

This is mostly based on How to make ssh-add read passphrase from a file? and using < /dev/null to force ssh-add to really call the askpass program.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .