如何使用相同的SSH公钥再次在github帐户上使用同一台笔记本电脑? [英] How to use same ssh public key again for another on github account same laptop computer?

查看:383
本文介绍了如何使用相同的SSH公钥再次在github帐户上使用同一台笔记本电脑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用我的电脑做了很多不同的事情,因为我确信很多开发者都这么做。但是我只有一个公共ssh密钥,我希望这样保持。我有两个github.com帐户:一个用于个人用途,另一个用于我的雇主。

因此,当我使用我的雇主的帐户时,我试图像我平时那样添加我的ssh密钥,点击配置文件,然后点击设置,然后点击ssh和gpg密钥。然后粘贴我的id_rsa.pub内容,然后单击添加ssh密钥。但它给了我以下:
$ b $ p

密钥已被使用



当然,这是因为我正在使用该密钥作为我的个人帐户。我如何让这个密钥也可以用于我的github的雇主帐户?感谢您。

作为额外的查询,我不明白为什么如果两个不同的帐户使用相同的公钥两次。那有什么害处?为什么github不允许这样做?



在主机级别和回购级别使用不同的ssh密钥似乎存在差异。

解决方案

正如其他人指出的那样,您需要生成两个密钥对。然后,当您需要在个人项目上使用个人密钥时,请按照以下方式克隆回购。

  ssh-agent bash  - c'ssh-add /home/< user> /.ssh/personal; git clone git@github.com:user / project.git'

对于雇主项目,克隆如下。

  ssh-agent bash -c'ssh-add /home/<user>/.ssh/employer; git clone git@github.com:user / project.git'

请注意 personal 雇主是各自的私钥名称。



在完成上述克隆之后,您不必担心键。 Git将使用您将克隆回购协议的SSH密钥用于该回购的所有未来操作。


I use my computer for many different things, as I’m sure many devs do. But I only have one public ssh key, and I hope to keep it that way. I have two accounts for github.com: one for personal use, and one for my employer.

So, when I am using the account with my employer, I’m trying to add my ssh key as I usually do, by clicking "Profile" and then "Settings" and then "ssh and gpg keys". And then I paste my id_rsa.pub contents, and click "add ssh key". But it is giving me the following:

"Key is already in use"

And of course that is because I am using that key for my personal account. How do I allow this key to also be used for my employer account with github? Thank you.

As an additional inquiry, I do not understand why it matters if the same public key is used twice for two different accounts. What is the harm in that? and why does github not allow that?

There seems to be a difference between committing using different ssh keys at the host level, and at the repo level.

解决方案

As others have pointed out, you need to generate two key pairs. And then when you need to work using your personal key on personal projects, clone the repo as follows.

ssh-agent bash -c 'ssh-add /home/<user>/.ssh/personal; git clone git@github.com:user/project.git'

For employer projects, clone as follows.

ssh-agent bash -c 'ssh-add /home/<user>/.ssh/employer; git clone git@github.com:user/project.git'

Note that personal and employer are the respective private key names.

After doing the cloning as above, you don't need to worry about the key. Git will use the SSH key you cloned the repo with for all future operations on that repo.

这篇关于如何使用相同的SSH公钥再次在github帐户上使用同一台笔记本电脑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆