Cannot push to git repository - permission denied
Asked Answered
B

9

52

I have a following problem:

$ git push -u origin master
Permission denied (publickey).
fatal: Could not read from remote repository.

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

I have already checked the connection doing this:

$ ssh -vT [email protected]

and output looks good, I was correctly authenticated.

While checking further, I noticed that:

$ ssh-add -l
The agent has no identities.

I have tried to run ssh-agent, but nothing changed:

$ ssh-agent
SSH_AUTH_SOCK=/tmp/ssh-A1mhFqvqncuO/agent.766; export SSH_AUTH_SOCK;
SSH_AGENT_PID=767; export SSH_AGENT_PID;
echo Agent pid 767;
$ ssh-add -l
Could not open a connection to your authentication agent.

I am using Arch Linux. Any help would be strong appreciated! Thanks in advance!

Github diagnostic help here.

Bushwhack answered 2/12, 2012 at 22:31 Comment(2)
show your ~/.ssh/configFebrile
My solution has been to regenerate my public key. Seems to work for me under Ubuntu.Commencement
I
126

I had the similar problem and my problem was solved by running the following command to add my key to the list of known keys:

ssh-add ~/.ssh/id_rsa

Hope it solves yours too. ;)

Inchmeal answered 1/8, 2013 at 12:4 Comment(1)
This has helped me so many times. Is there a way to just permanently add this so i don't always have to go through the motions.Wisteria
B
6

If you haven't already read it, you should look through the GitHub help page for this error:

Error: Permission denied (publickey)

Every time that I've had this problem, it was due to the last issue listed on that page: I didn't have the public key from my current workstation attached to my GitHub account. Of course, GitHub also provides instructions on how to attach your public key to your account.


tl;dr

Make sure your current public key is attached to your GitHub account.

Blackboard answered 2/12, 2012 at 22:37 Comment(2)
Yes, I've read this and my public key is attached to my github account.Bushwhack
Dang. If the public key for the current user on your current machine matches the one registered in github then I'm not going to be of any help—that's been my problem every time I've run into this error.Blackboard
S
6

You need to do in your console (if you use an a putty ssh client):

  1. Generate the keys, if keys not exist:

    cd ~/.ssh && ssh-keygen -lf ~/.ssh/id_rsa.pub
    

Don't forget password, entered at this step!

  1. Output your public key to screen:

    cd ~/.ssh && cat id_rsa.pub
    
  2. Copy this string by click and move a mouse pointer from begin output to end. No need to press Ctrl + V or any more keys.

  3. Log in your account on GitHub and add this public key to https://github.com/settings/ssh

  4. Now you can use your git locally.

Sedan answered 9/10, 2013 at 2:50 Comment(0)
P
4

I don't think this will solve your problem since you tested ssh -vT [email protected] directly and it worked, but you are using the ssh-agent improperly. You need to run

$ eval `ssh-agent -s`
Agent pid 767
$ ssh-add -l
The agent has no identities.

This will evaluate the environment export commands and allow your ssh-add and ssh commands to communicate with the agent. Alternatively, you can ask the agent to start a shell, terminal, etc. and it will set up the proper environment:

$ ssh-agent bash
$ ssh-add -l
The agent has no identities.

In this case, the shell is running as a child of the ssh-agent and the agent will shut down when the shell quits.

Ponderous answered 14/6, 2013 at 20:35 Comment(0)
D
3

I faced the same issue on my Ubuntu and then I realize that I am on sudo mode, once I just access remote without sudo it went well.

That's how I get rid if the issue, hope it may help.

Doublebreasted answered 19/9, 2013 at 12:39 Comment(0)
E
2

Permission denied (public key). I encountered this problem today, but I found a solution finally, and successfully solved my problem.

Maybe you should verify following issues:

  1. you have a github account
  2. git config your username and -mail
  3. generate a ssh-key pri/pub pair and add the public key to your git account, please check this may give you help: generating new ssh key and cannot push git repository 'permission denied'
  4. check that ssh-key is successfully added: ssh -V [email protected]
  5. good luck!
Exo answered 14/2, 2016 at 14:54 Comment(0)
L
2

In my case I had this problem with GitLab because I was working with non-default SSH key pair paths. @NEO 's answer works perfectly:

ssh-add ~/.ssh/other_id_rsa

However, I had to do this everytime that I opened a new terminal.

To make this change permanent, you have to edit ~/.ssh/config and add the following:

Host gitlab.company.com
RSAAuthentication yes
IdentityFile ~/.ssh/config/private-key-filename

For more detailed info check gitlab's documentation.

Luce answered 26/4, 2018 at 8:50 Comment(0)
F
0

I'd try this out from (Pushing to Git returning Error Code 403 fatal: HTTP request failed):

To definitely be able to login using https protocol, you should first set your authentication credential to the git Remote URI:

git remote set-url origin https://[email protected]/user/repo.git

Then you'll be asked for a password when trying to git push.

Fetal answered 31/8, 2020 at 12:27 Comment(0)
A
-1

fatal: unable to access 'https://......': The requested URL returned error: 403 if you when push your code and see this Error you follow this address in windows

⇒ Control Panel\User Accounts\Credential Manager and remove past account in GitHub

Attic answered 30/9, 2020 at 6:34 Comment(1)
The poster has specified that he had this problem under Arch LinuxRonen

© 2022 - 2024 — McMap. All rights reserved.