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.