ERROR: Permission to xyz/private-repo.git denied to x


I am using two git accounts on the same Mac, one for Work and one for Personal dev. I used to use ssh access for the accounts. I generated the SSHs and added them to the config file.

I am using the this config file

Host x-GitHub
    User x
    PreferredAuthentications publickey
    IdentityFile /Users/siyum/.ssh/x-GitHub
    UseKeychain yes
    AddKeysToAgent yes

Host Nethsara
    PreferredAuthentications publickey
    IdentityFile /Users/siyum/.ssh/nethsara

Now I cloned a private repo from my personal one, Which is Nethsara and it cloned successfully.

I used this to clone

% git clone git@Nethsara:Nethsara/private-repo.git

But when I tried to commit and push a change it is giving me this error.

ERROR: Permission to Nethsara/private-repo.git denied to x. fatal:
Could not read from remote repository.

Please make sure you have the correct access rights and the repository

My global username is already set to Nethsara.

% git config –global

What could be go wrong?

>Solution :

I see a couple things you can fix.

First, SSH connections to GitHub all happen with the username git. Either change your ~/.ssh/config to include the line User git instead of that User x, or remove that line and be sure that all remotes include git@ before your custom hostnames.

Second, since you’re working with multiple identities, add IdentitiesOnly yes to each stanza. This will prevent the agent from even bothering with other known identities, and only use the one specified in the config file.

Finally, you can test SSH connections to GitHub with ssh -T git@x-GitHub and ssh -T git@Nethsara – if things are configured properly in your ~/.ssh/config, you should get a message with the correct GitHub username for each.

Leave a ReplyCancel reply