Rana
Rana

Reputation: 6154

Composer Github private repository not working with given key

I was trying to get a private repository from Github installed via composer. My composer configuration is as below:

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

However, it doesn't work with this configuration. It's still asking for github user/pass. However, if my system's github authorization is set up properly with keys, only then it works automatically.

In any way, composer configuration isn't working. Is anybody else facing the same issue or is there anything I did wrong/need to check here? Thanks in advance.

Upvotes: 7

Views: 5941

Answers (3)

Jens
Jens

Reputation: 1

In addition to this answer of kkochanski (Sorry, i have not enough reputation to comment his answer):

His solution didn't work for me. I had to use a slash instead of a colon:

"repositories": [
    {
        "type": "vcs",
        "url": "ssh://[email protected]/[user]/[repo].git"
    }
],

Upvotes: -1

kkochanski
kkochanski

Reputation: 2287

In my case, instead of passing just a plain repo URL like this [email protected]:{user}/{repo}.git, I needed to add ssh:// prefix. So it ended to look like this: ssh://[email protected]:{user}/{repo}.git. Then it worked.

I didn't need to give a path for the private key. That was grabbed from the .ssh folder.

"repositories": [
        {
            "type": "vcs",
            "url":  "ssh://[email protected]:{user}/{repo}.git",
        }
    ]

Upvotes: 1

scipilot
scipilot

Reputation: 7447

I'm not sure what your problem is, but you could solve it another way using an ssh config file.

This allows you to configure SSH connections to use specific credentials for 'virtual' hosts, which thus allows you to alter the way you connect to Git repos, and therefore can be used to modify Composer dependencies which use ssh.

Edit ~/.ssh/config e.g.

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

Then modify your composer.json to use the fake host and remove the ssh options:

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

So when ssh tries to connect to the 'virtual' host ranacseruet_github.com, it will use the credentials specified.

I use this technique to define git remotes which need specific credentials. It should work exactly the same via composer, as it is a more general solution at the ssh-level.

Upvotes: 2

Related Questions