Can I make Magit add my ssh passphrase to ssh-agent instead ask me to use the passphrase a single time?

Every time I push a commit to my remote I need to type my passphrase or instead run M-& ssh-add PATH_TO_MY_CREDENTIAL to add it to my ssh-agent.

  • 2
    What OS are you running? How are you starting ssh-agent?
    – npostavs
    Mar 21, 2018 at 14:20
  • I'm running Ubuntu, I don't know exactly how ssh-agent was starting, but when I run ssh-add CREDENTIAL I don't need to type my password again.
    – squiter
    Mar 21, 2018 at 16:42

1 Answer 1


You can use the ssh-agency package for this. It integrates with magit, and will run ssh-add as needed when you push. If you don't have ssh-askpass installed, you will need a version which includes this fix (pushed Apr 4, 2018) to successfully prompt for a passphrase on a Unixish system.

Note: I'm the author of this package.

  • I don't know if it requires a little of configuration, but it doesn't work for me... I installed using MELPA and add (require 'ssh-agency). Then I did the test and the result was the same that I described in my question.
    – squiter
    Mar 22, 2018 at 13:02
  • Ideally it shouldn't require any configuration. What's the result of echo $SSH_AUTH_SOCK, echo $SSH_AUTH_PID, and ssh-add -l; echo $? in a terminal; (getenv "SSH_AUTH_SOCK"), and (ssh-agency-status) in Emacs?
    – npostavs
    Mar 22, 2018 at 13:33
  • echo $SSH_AUTH_PID : /tmp/ssh-OfgrvDM7CUHq/agent.1750 same result of (getenv "SSH_AUTH_SOCK"), now the echo $SSH_AUTH_PID returns nothing, ssh-add -l;echo $? returns "The agent has no identities." and "1", (ssh-agency-status) has returned no-keys. Before run this comands I tried to push commits im my remote twice and all the time it requested me my passphrase.
    – squiter
    Mar 22, 2018 at 19:18
  • Oh, I just realized I overlooked something, is PATH_TO_MY_CREDENTIAL some non-standard path (i.e., not one of ~/.ssh/id_rsa, ~/.ssh/id_dsa, ~/.ssh/id_ecdsa, or ~/.ssh/id_ed25519)? If so, you need to customize ssh-agency-keys.
    – npostavs
    Mar 22, 2018 at 19:45
  • But I think the content of ssh-agency-keys is right! When I get the variable content, it shows ~/.ssh/id_rsa and ~/.ssh/id_rsa_gateway. And this is the current keys I have in this host.
    – squiter
    Mar 23, 2018 at 12:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.