Github ssh key didn't work

Check the git URL configuration of your project

Posted by yaohong on Sunday, September 5, 2021

TOC

Github ssh key didn’t work

After you config a ssh key on github, you can test your ssh connection.

  • 1.Open Terminal.
  • 2.Enter the following:
$ ssh -T git@github.com

If you see your username of github in the resulting message, that means you configure successfully.

But, when you run git pull under the root of the project, the it prompt you to enter your Username of github, what is wrong?!

Now you should check that the URL in git config file starts with git@, instead of the http or https:

You can verify it by switching command line to the root of your project, and run cat .git/config to see the URL of git.

Find the line that starts with url = , if the value of this URL starts with http, then replace it with the one started with`git@github.com:<username_of_github>/<project_name>.git`;

For example, this configuration of git URL will not use ssh key(note the value of url):

[remote "origin"]
    url = https://github.com/Yaohong9257/YaoHong.git
    fetch = +refs/heads/*:refs/remotes/origin/*

The correct url to use ssh key (note the value of url):

[remote "origin"]
    url = git@github.com:Yaohong9257/YaoHong.git
    fetch = +refs/heads/*:refs/remotes/origin/*

「点个赞」

Yaohong

点个赞

使用微信扫描二维码完成支付