简体   繁体   English

多个 github 存储库的 SSH 密钥

[英]SSH key for multiple github repositories

I followed this guide to set up an SSH key pair for a github repo:我按照本指南为 github 存储库设置了 SSH 密钥对:

https://linuxkamarada.com/en/2019/07/14/using-git-with-ssh-keys/#.YNNfCDZKjRZ https://linuxkamarada.com/en/2019/07/14/using-git-with-ssh-keys/#.YNNfCDZKjRZ

Shouldn't this key work for my account in general, ie 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.我已经有了密钥对,它存储在我的 GitHub 帐户中,并且 GitHub 已添加到我的受信任主机中。

GitHub provides two main ways to access a repository: HTTPS and SSH. GitHub 提供了两种访问存储库的主要方式:HTTPS 和 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 .如果您在帐户设置中设置了 SSH 密钥,那么您应该能够使用它推送到您有权访问的任何存储库,前提是您使用的是 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.但是,如果系统提示您使用用户名和密码,那么您使用的是 HTTPS,而不是 SSH,因为 GitHub 不通过 SSH 协议提供用户名和密码访问。

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.如果要将 SSH 用于不同的存储库,请转到 Web 界面中的存储库并从下拉列表中复制 SSH URL。 Then go into that repository and run git remote -v .然后进入该存储库并运行git remote -v That should show you all the remotes that you have and their URLs.这应该会显示您拥有的所有遥控器及其 URL。 Assuming the remote name you want to change is called origin , run the following where URL is the SSH URL you've copied:假设您要更改的远程名称名为origin ,请运行以下命令,其中URL是您复制的 SSH URL:

$ git remote set-url origin URL

That will set up that repository to use SSH instead of HTTPS.这将设置该存储库以使用 SSH 而不是 HTTPS。

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:这也可能是因为,对于第二个存储库,您输入了错误的 SSH URL,例如:

<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.确保您的 URL 是第二种形式,使用git作为远程用户。

And to check if SSH is involved:并检查是否涉及 SSH:

git -c core.sshCommand='ssh -Tv" push

You will see what SSH key is used then.然后您将看到使用了什么 SSH 密钥。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM