5

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 foobar@github.com (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?

Jonta
  • 147
  • 6
irregular
  • 962
  • 1
  • 9
  • 21

2 Answers2

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.

db48x
  • 15,741
  • 1
  • 19
  • 23
  • 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 Feb 20 '17 at 03: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. – Philippe Fanaro May 05 '21 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 May 05 '21 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. – Philippe Fanaro May 05 '21 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 May 05 '21 at 22:08
  • I've created a [post](https://stackoverflow.com/q/67423957/4756173) about this issue on StackOverflow, as I believe it is broader than only Emacs. – Philippe Fanaro May 06 '21 at 18:25
3

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/

irregular
  • 962
  • 1
  • 9
  • 21