Ronin
Ronin

Reputation: 2957

Github SSH Permission denied to deploy key

I created a fresh repo, was able to clone with SSH and commit and everything. But when I try to push I get the following error:

ERROR: Permission to Ronin11/MealPlanr.git denied to deploy key
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

Using:

ssh -T [email protected]

I was able to verify that my ssh key is working. I have no idea what happened. This was just working the other day. I haven't touched these settings in months. All this was using the terminal on Mac.

Help!

Upvotes: 18

Views: 26729

Answers (8)

Selam Selam
Selam Selam

Reputation: 61

For mac users!

as #sashaboulouds has mentioned earlier, when you run this code in ur terminal

$ ssh -T -ai ~/.ssh/id_rsa [email protected]

You will get a message like this

"Hi yourName ! You've successfully authenticated, but GitHub does not provide shell access."

if you see any project name next to your user name (like userName/repositoryName , you definitely used ur public ssh key to a single repo.

The solution is

  • copy your public key from your terminal/command line by running

    $ cat ~/.ssh/id_rsa.pub

and go to your github account

  • under your “repositoryName” repo

    • delete the already attached public key
  • under your GitHub username account setting

    • click on SSH and GPG keys
    • add a new SSH key
    • fill in the title and paste the public key in the key area provided

Test it

run $ ssh -T -ai ~/.ssh/id_rsa [email protected]

if you see the message with your GitHub account only. you have successfully assigned the public to your account as a whole.

Upvotes: 0

Wilhelm de Fheur Gorm
Wilhelm de Fheur Gorm

Reputation: 339

For me the problem was that I already had a key defined specifically for github.com in my ~/.ssh/config file. I erroneously added a public key that was not the one I had in the config file. Without using the verbose option, you'll get a message everything is fine. With verbose option (ssh -vT [email protected]), the output will start providing clues regarding line numbers like

debug1: Reading configuration data /home/user/.ssh/config debug1: /home/user/.ssh/config line 66: Applying options for github.com

Where my ~/.ssh/config file has this in it

Host github github.com
HostName github.com etc

It seems obvious after the fact, but.. ensure you're using the correct public key that corresponds to any specific entries for gihub listed in your config file.

Upvotes: 1

Josh Hibschman
Josh Hibschman

Reputation: 3714

Yet another might be that your id_rsa private key file has too broad of permissions, e.g. 0644, and the error is getting buried.

Restrict the perms:

chmod 400 ~/.ssh/id_rsa

Note: you'll need to re-add the key to ssh-agent

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_rsa

And test again:

ssh -T -ai ~/.ssh/id_rsa [email protected]

Upvotes: 5

damask
damask

Reputation: 555

The probable answer to your issue is that you are using a deploy key which usually only has read access. If it did have write access at one stage, perhaps someone has changed it back to read only.

Upvotes: 0

Chetan Pangam
Chetan Pangam

Reputation: 370

Solution 1:

ssh-agent bash -c 'ssh-add ~/.ssh/id_rsa; your_git command'

In this case, you have to repeat the above command by appending your git command each time. I would not recommend this.

Solution 2:

ssh-add -D
ssh-add ~/.ssh/id_rsa

These two commands will remove ad add the SSH keys for a single sign-on.

Upvotes: 3

sashaboulouds
sashaboulouds

Reputation: 1854

It's possible that your key is already linked to one repo.

Try to use ssh -T -ai ~/.ssh/id_rsa [email protected] to find the concerned repo.

All details here https://help.github.com/en/articles/error-key-already-in-use

Upvotes: 17

Pedro Muñoz
Pedro Muñoz

Reputation: 700

For me the following always works for GitHub push:

eval `ssh-agent -s`; ssh-add your_key; git push

Upvotes: 15

Derek Hunter
Derek Hunter

Reputation: 191

You mentioned you were using OSX. If you're on 10.12.2+ it may be a problem with your ssh config. Github's documentation has a note about that.

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/

Specifically they say add the following to ~/.ssh/config

Host * AddKeysToAgent yes UseKeychain yes IdentityFile ~/.ssh/id_rsa

Hope this helps

Upvotes: 9

Related Questions