1

I use GitHub to manage my code. And I have already add my public ssh key which generated through ssh-keygen command.

However, it needs me to provide username and password when I want to push using git push command. And GitHub shows that my SSH key is never used. I don't want to give username and password every time.

iBug
  • 35,554
  • 7
  • 89
  • 134
nail fei
  • 2,179
  • 3
  • 16
  • 36
  • 1
    Possible duplicate of [Git keeps prompting me for password](https://stackoverflow.com/questions/7773181/git-keeps-prompting-me-for-password) – phd Jan 21 '18 at 15:15

2 Answers2

2

Try changing the remote URL:

git remote set-url origin git@github.com:user/repository

In this way Git will communicate in the SSH protocol rather than the (possibly) HTTPS protocol, which is the reason you're asked for username and password every time.

I personally have this in my $HOME/.ssh/config:

Host GitHub github
    HostName github.com
    User git
    IdentityFile ~/.ssh/id_rsa
    PubKeyAuthentication yes

And I set the remote URL for my local repositories as

git remote set-url origin GitHub:iBug/SomeRepo

You can verify you have the correct remote URL set with git remote get-url origin:

ibug@linux:~/myrepo $ git remote get-url origin
git@github.com:iBug/myrepo

If the SSH remote host is correctly configured, try ssh -T github:

ibug@linux:~ $ ssh -T -i ~/.ssh/id_rsa git@github.com
Hi iBug! You've successfully authenticated, but GitHub does not provide shell access.
iBug
  • 35,554
  • 7
  • 89
  • 134
1

You need to add that public key to your GitHub account.

And you need to check a simple ssh -T git@github, ie you see a "Welcome" message.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250