Reputation: 2962
I followed this guide to set up an SSH key pair for a github repo:
https://linuxkamarada.com/en/2019/07/14/using-git-with-ssh-keys/#.YNNfCDZKjRZ
Shouldn't this key work for my account in general, i.e. should work for ay repo I push to? It seems to be working for the repo that I originally set it up for, but not for a new repo that I've since created, under the same account. Do I need to repeat any of these steps? Most of them seem like they should not be repeated; I already have the key pair, it is stored on my GitHub account, and GitHub is added to my trusted hosts.
Upvotes: 2
Views: 2576
Reputation: 1323553
I have a public key added at that link. And for one of my repos it works, and for another, I'm getting a password prompt –
That could happen also because, for the second repository, you have entered an incorrect SSH URL, like:
<me>@github.com:<me>/<myRepository.git>
# instead of:
[email protected]:<me>/<myRepository.git>
Make sure your URL is of the second form, using git
as remote user.
And to check if SSH is involved:
git -c core.sshCommand='ssh -Tv" push
You will see what SSH key is used then.
Upvotes: 0
Reputation: 76409
GitHub provides two main ways to access a repository: HTTPS and SSH. If you've set up an SSH key in your account's settings, then you should be able to use it to push to any repository you have access to provided you're using SSH. However, if you're being prompted to use a username and password, then you're using HTTPS, not SSH, since GitHub does not offer username and password access over the SSH protocol.
If you want to use SSH with a different repository, go to the repository in the web interface and copy the SSH URL from the drop-down. Then go into that repository and run git remote -v
. That should show you all the remotes that you have and their URLs. Assuming the remote name you want to change is called origin
, run the following where URL
is the SSH URL you've copied:
$ git remote set-url origin URL
That will set up that repository to use SSH instead of HTTPS.
Upvotes: 1