github部署密钥:我如何为单个机器授权多个存储库 [英] github deploy keys: how Do I authorize more than one repository for a single machine
问题描述
rob
。我在 rob
上使用了ssh-keygen来获取一个公钥,这是我给github添加一个新的部署密钥屏幕给仓库 cheech 。现在我想在 rob
上部署 chong
。但是,如果我在github上为存储库 chong
添加新的部署密钥屏幕,并粘贴我在 rob $ c上生成的公钥$ c>它表示键已被使用
。我想,如果他们的关键在使用中,我可以在 rob
上克隆 chong
,但是表示权限被拒绝。
显然,这比我想象的要复杂得多,它涉及到拥有多个键或其他东西。我应该如何在 rob
?
chong
>感谢您的帮助。
解决方案一旦一个密钥已作为部署密钥附加到一个回购协议,它不能是
用于另一个回购。如果您在设置
部署密钥时遇到此错误,则需要修改远程设置并设置您的
〜/ .ssh / config
文件来使用不存在的 github.com主机名
ssh可以用来为你的
仓库选择正确的ssh部署密钥。 #
#首先删除原点
$ git remote -v $ b $原点git@github.com:用户名/ foo.git(fetch)
origin git@github.com:username / foo.git(push)
$ git remote rm origin
这里我们添加一个新的原点一个名为
#foo.github.com的主机昵称,我们将在
#〜/ .ssh / config中的一个主机节中引用它来指定哪个密钥与哪个虚拟主机名一起使用。
$ git remote add origin git@fake-hostname-foo.github.com:username / foo.git
$ git remote -v
origin git@fake-hostname-foo.github。 com:username / foo.git(fetch)
origin git@fake-hostname-foo.github.com:username / foo.git(push)
$ p
$ b为你的仓库生成部署密钥,并将其命名为
合理,如:
$ ssh-keygen -t rsa -f〜/ .ssh / id_rsa-foo -C https://github.com/username/foo
生成公钥/私钥rsa密钥对。
输入密码(没有密码时为空):
再次输入相同密码:
您的身份已保存在/home/username/.ssh/id_rsa-foo中。
您的公钥已保存在/home/username/.ssh/id_rsa-foo.pub中。
关键指纹是:
c0:ff:ee:34:24:11:5e:6d:7c:4c:b1:a0:de:ad:be:ef https:// github。 com / username / foo
密钥的randomart图像是:
+ - [RSA 2048] ---- +
| E o..o.oo。 |
| M o o o。+ CoW |
| + o = o。 .. |
| 。 。 + |
| S |
| o。 |
| + |
| 。 o |
| ..o。 |
+ ----------------- +
一旦您
添加了部署密钥 $ b $然后您需要将以下节添加到〜/ .ssh / config
文件中:
主机fake-hostname-foo.github.com
主机名github.com
IdentityFile〜/ .ssh / id_rsa-foo
现在您可以用以下方式测试它:
$ ssh -T git@fake-hostname-foo.github.com
您好用户名!您已成功通过身份验证,但GitHub
不提供shell访问权限。
So, I have a host, call it rob
. I used ssh-keygen on rob
to get a public key, which I gave to github in the add a new deploy key screen for repository cheech
. Now I want to deploy chong
on rob
as well. But if I go to the add new deploy key screen for repository chong
on github, and paste in the public key I generated on rob
it says key already in use
. I thought, if they key was in use, I could clone chong
on rob
but that says permission denied.
So clearly this is more complicated than I thought and it involves having multiple keys or something. What should I do to clone chong
on rob
?
Thank you for your help.
解决方案 Once a key has been attached to one repo as a deploy key, it cannot be
used on another repo. If you're running into this error while setting
up deploy keys, then you'll need to modify your remote and set up your
~/.ssh/config
file to use a non-existent github.com hostname that
ssh will be able to use to pick the correct ssh deploy key for your
repository.
# first we remove the origin
$ git remote -v
origin git@github.com:username/foo.git (fetch)
origin git@github.com:username/foo.git (push)
$ git remote rm origin
# here we add a new origin using a host nickname called
# foo.github.com that we will reference with a Host stanza in our
# ~/.ssh/config to specify which key to use with which fake hostname.
$ git remote add origin git@fake-hostname-foo.github.com:username/foo.git
$ git remote -v
origin git@fake-hostname-foo.github.com:username/foo.git (fetch)
origin git@fake-hostname-foo.github.com:username/foo.git (push)
Generate the deploy key for your repository and name it something
reasonable like:
$ ssh-keygen -t rsa -f ~/.ssh/id_rsa-foo -C https://github.com/username/foo
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/username/.ssh/id_rsa-foo.
Your public key has been saved in /home/username/.ssh/id_rsa-foo.pub.
The key fingerprint is:
c0:ff:ee:34:24:11:5e:6d:7c:4c:b1:a0:de:ad:be:ef https://github.com/username/foo
The key's randomart image is:
+--[ RSA 2048]----+
| E o..o.oo. |
| M o o o .+CoW |
| + o = o. .. |
| . . + |
| S |
| o . |
| + |
| . o |
| ..o. |
+-----------------+
Once you've
added the deploy key
you will then need to add the following stanza to your ~/.ssh/config
file:
Host fake-hostname-foo.github.com
Hostname github.com
IdentityFile ~/.ssh/id_rsa-foo
Now you can test it with:
$ ssh -T git@fake-hostname-foo.github.com
Hi username! You've successfully authenticated, but GitHub
does not provide shell access.
这篇关于github部署密钥:我如何为单个机器授权多个存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!