2

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.

pretzlstyle
  • 2,774
  • 5
  • 23
  • 40
  • 1
    Please don't make us read and follow this guide you linked, instead, show us the current situation, expectations and the issues you face. What key are you exactly talking about? Because in GitHub, you have several different keys on a different basis. – Daniel W. Jun 23 '21 at 16:38
  • I dont understand what you mean by `Shouldn't this key work for my account in general` . Are you talking about not entering your passwd everytime you `push` ? That work is done by an `ssh-agent` which caches the decrypted private key for the session. Also [check this](https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh/testing-your-ssh-connection) – Jdeep Jun 23 '21 at 16:44
  • A (public) key you store in https://github.com/settings/keys is able to read/write to all of your repositories. – Daniel W. Jun 23 '21 at 16:45
  • @DanielW. yes, that is exactly my confusion. 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 – pretzlstyle Jun 23 '21 at 17:22
  • @pretzlstyle yes you will get a password prompt everytime you log out. After logging in, you need to enter it once and push as many times you want without enter passwd. Thats the work of ssh agent – Jdeep Jun 23 '21 at 17:48
  • @Jdeep I understand that, but this isn't working; for one repo, it does, but for another, I'm prompted for a password on every push. Both of these repos are held by the same github account. That's wy I ask if there isanything that needs to be done at the repo-level to enable this to work – pretzlstyle Jun 23 '21 at 18:06
  • @pretzlstyle [I think this is the problem that you are facing](https://stackoverflow.com/questions/18880024/start-ssh-agent-on-login) – Jdeep Jun 23 '21 at 18:18
  • 1
    Are you using ssh URLs for both repositories? – torek Jun 23 '21 at 22:37

2 Answers2

1

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.

bk2204
  • 64,793
  • 6
  • 84
  • 100
0

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:
git@github.com:<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.

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