简体   繁体   English

如何设置多个Github部署密钥(npm,yarn)?

[英]How to set up multiple Github deployment keys (npm, yarn)?

I have an npm project that depends on several private Github repositories. 我有一个npm项目,它依赖于几个私有的Github存储库。 I am deploying the project on staging server, and I have set up separate deploy keys for each private repository, as Github does not allow to use the same key for each. 我正在临时服务器上部署项目,并且为每个私有存储库设置了单独的部署密钥,因为Github不允许为每个私有密钥使用相同的密钥。 I have set up ~/.ssh/config like this: 我已经这样设置〜/ .ssh / config:

Host 1.github.com
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/key-1
        StrictHostKeyChecking no

Host 2.github.com
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/key-2
        StrictHostKeyChecking no

Host 3.github.com
        HostName github.com
        User git
        PreferredAuthentications publickey
        IdentityFile ~/.ssh/key-3
        StrictHostKeyChecking no

In package.json, I have the following private Github repository dependencies: 在package.json中,我具有以下私有Github存储库依赖项:

"project1": "git+ssh://git@github.com/myorg/project1.git",
"project2": "git+ssh://git@github.com/myorg/project2.git",
"project3": "git+ssh://git@github.com/myorg/project3.git"

However, this does not work and I'm getting Permission denied (publickey) error. 但是,这不起作用,并且我收到Permission denied (publickey)错误。 The projects are also being used by users who access the repositories with their Github accounts. 通过其Github帐户访问存储库的用户也正在使用这些项目。

How do I get the keys working? 如何使按键起作用?

If you want to use different keys for different github accounts, you need to modify the git urls by using the alias defined in the configuration files, such as: 如果要对不同的github帐户使用不同的密钥,则需要使用配置文件中定义的别名来修改git url,例如:

"project1": "git+ssh://git@1.github.com/myorg/project1.git",
"project2": "git+ssh://git@2.github.com/myorg/project2.git",
"project3": "git+ssh://git@3.github.com/myorg/project3.git"

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

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