Composer Github私有存储库无法使用给定的密钥

时间:2014-06-29 18:52:46

标签: php github ssh composer-php ssh-keys

我试图通过composer从Github安装私有存储库。我的composer配置如下:

"repositories": [
            {
                "type": "vcs",
                "url":  "git@github.com:{user}/{repo}.git",
                "options": {
                    "ssh2": {
                        "user": "ranacseruet" 
                        "privkey_file": "./keys/id_rsa",
                        "pubkey_file": "./keys/id_rsa.pub"
                    }
                }
            }
        ]

但是,它不适用于此配置。它仍然要求github用户/通行证。但是,如果我的系统的github授权是使用密钥正确设置的,那么它只能自动运行。

无论如何,作曲家配置都不起作用。是否有其他人面临同样的问题,或者有什么我做错了/需要在这里检查?提前谢谢。

3 个答案:

答案 0 :(得分:1)

我不确定您的问题是什么,但您可以使用ssh config file以另一种方式解决问题。

这允许您配置SSH连接以使用特定凭据进行虚拟' hosts,因此允许您改变连接到Git repos的方式,因此可用于修改使用ssh的Composer依赖项。

编辑〜/ .ssh / config例如

Host ranacseruet_github.com
User git
HostName github.com
IdentityFile [path-to]/keys/id_rsa

然后修改您的composer.json以使用虚假主机并删除ssh选项:

"repositories": [
    {
        "type": "vcs",
        "url":  "git@ranacseruet_github.com:{user}/{repo}.git",
    }
]

所以当ssh试图连接到虚拟'主机ranacseruet_github.com,它将使用指定的凭据。

我使用这种技术来定义需要特定凭据的git遥控器。它应该通过composer完全相同,因为它是ssh级别的更通用的解决方案。

答案 1 :(得分:0)

在我的情况下,我需要添加git@github.com:{user}/{repo}.git前缀,而不是仅传递诸如ssh://这样的普通回购URL。因此,它看起来像这样:ssh://git@github.com:{user}/{repo}.git。然后它起作用了。

我不需要为私钥提供路径。这是从.ssh文件夹中获取的。

"repositories": [
        {
            "type": "vcs",
            "url":  "ssh://git@github.com:{user}/{repo}.git",
        }
    ]

答案 2 :(得分:0)

除了这个answer的kkochanski(对不起,我没有足够的声誉来评论他的回答):

他的解决方案对我不起作用。我必须使用斜杠而不是冒号:

"repositories": [
    {
        "type": "vcs",
        "url": "ssh://git@github.com/[user]/[repo].git"
    }
],