6

I've seen the question here but I'm not sure if the same solution would apply to me

Magit, how to use system's ssh agent and don't ask for password

I'm on Emacs 25.1 / Ubuntu 16.04. I've just set up SSH-keys according to https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/ and I've added the public key to my GitHub account.

When I try to push though, Magit prompts me for my password to my account [email protected] (as always) rather than seeing that I've set an SSH-key into ssh-agent.

M-x getenv SSH_AGENT_PID doesn't exist and M-x getenv SSH_AUTH_SOCK is /run/user/1000/keyring/ssh. echo $SSH_AGENT_PID is 18145. What is the next step from here?

1
  • M-x setenv SSH_AGENT_PID 18145?
    – npostavs
    Commented Feb 20, 2017 at 0:06

2 Answers 2

5

Edit ~/.ssh/config so that it contains the following:

Host github.com
  IdentitiesOnly yes
  IdentityFile ~/.ssh/your_ssh_key

Then whenever magit asks git to ask ssh to talk to github.com, ssh will know what key to use; saves a lot of mucking about.

6
  • The issue was I had the remote url set to https instead of ssh, I posted an answer for other people to see. I think you answer is useful for learning more about how the ~/.ssh/config works though, I think I'll need to refer to it in the future, thanks
    – irregular
    Commented Feb 20, 2017 at 3:26
  • So close and yet so far... I put this on, but then Magit ends up in a loop. No matter how many times I type the password correctly, the prompt comes back.
    – psygo
    Commented May 5, 2021 at 21:07
  • If you use this configuration, and your git repository is using an ssh url, then Magit will not ask you for your github password. It might ask you for the password to your ssh key though, if the key is password protected. Are you sure you entered the correct password?
    – db48x
    Commented May 5, 2021 at 21:28
  • It says Enter passphrase for key ..., so I believe it is asking for the password to the correct file, which is the exact same I've been using with my terminal and Vim for quite a while. I've tested the password on the terminal a dozen times, it's the same.
    – psygo
    Commented May 5, 2021 at 21:32
  • Could be a bug, but check first to see if Magit is just performing multiple operations. Use $ to open a log buffer before you do whatever you do that needs the key.
    – db48x
    Commented May 5, 2021 at 22:08
5

The issue was that the remote url was set to https rather than ssh

following these steps fixed the issue https://help.github.com/articles/changing-a-remote-s-url/

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.