Github permission denied: ssh add agent has no identities

198,279

Solution 1

Full details in this answer.

In summary, when ssh-add -l returns “The agent has no identities”, it means that keys used by ssh (stored in files such as ~/.ssh/id_rsa, ~/.ssh/id_dsa, etc.) are either missing, they are not known to ssh-agent, which is the authentication agent, or that their permissions are set incorrectly (for example, world writable).

If your keys are missing or if you have not generated any, use ssh-keygen -t rsa, then ssh-add to add them.

If keys exist but are not known to ssh-agent (like if they are in a non-standard folder), use ssh-add /path/to/my-non-standard-ssh-folder/id_rsa to add them.

See this answer if you are having trouble with ssh-add or ssh-agent.

Solution 2

try this:

ssh-add ~/.ssh/id_rsa

worked for me

Solution 3

THE 2019 ANSWER for macOS Sierra & High Sierra & Catalina:

PS: most of the other answers will have you to create a new ssh key ... but you don't need to do that :)

As described in detail on https://openradar.appspot.com/27348363, macOS/OS X till Yosemite used to remember SSH keys added by command ssh-add -K <key>

So here are the 4 steps i had to take in order for it to work:

1: ssh-add ~/.ssh/PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)

2: Add the following in ~/.ssh/config

Host * 
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile PATH_TO_YOUR_SSH_PRIVATE_KEY (e.g. ~/.ssh/id_rsa)

3: make sure to remove any gitconfig entry that use osxkeychain helper:

 https://github.com/gregory/dotfiles/commit/e38000527fb1a82b577f2dcf685aeefd3b78a609#diff-6cb0f77b38346e0fed47293bdc6430c6L48

4: restart your terminal for it to take effect.

Solution 4

I have been stucked a while on the same problem, which I eventually resolved.

My problem: I could not execute any push. I could check & see my remote (using git remote -v), but when I executed git push origin master, it returned : Permission denied (publickey). fatal: Could not read from remote repository. and so.

How I solved it :

  • I generated a key using ssh-keygen -t rsa. Entering a name for the key file (when asked) was useless.
  • I could then add the key (to git): ssh-add /Users/federico/.ssh/id_rsa , which successfully returned Identity added: /Users/myname/.ssh/id_rsa (/Users/myname/.ssh/id_rsa)
  • I added the SSH key to github using this help page.
  • Having tried all the commands in Github's 'Permission denied publickey' help page, only the ssh-add -l command worked / seemed useful (after having ran the previous steps), it successfully returned my key. The last step shows you where to check your public key on your GitHub page. And this command will help you check all your keys : ls -al ~/.ssh.

Then the push command eventually worked !

I hope this will help ! Best luck to all.

Solution 5

Run the following commands:

ssh-keygen -t rsa
ssh-add /Users/*yourUserNameHere*/.ssh/id_rsa** 
pbcopy < ~/.ssh/id_rsa.pub**

Go to your Github account : https://github.com/settings/profile

1) Click : SSH and GPG keys

2) New SSH Key and Past it there

3) Add SSH Key

Done!

Share:
198,279

Related videos on Youtube

Dark
Author by

Dark

Updated on July 08, 2022

Comments

  • Dark
    Dark almost 2 years

    This is my first time accessing GitHub and I'm not experienced using a console. I am on a MacBook using Bash. When I try to access GitHub, I get this:

    git clone [email protected]:dhulihan/league-of-legends-data-scraper.git
    Cloning into 'league-of-legends-data-scraper'...
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    I've tried following the instructions on Github page about permission being denied.

    When I use ssh -vT [email protected], I get the following:

    OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
    debug1: Reading configuration data /etc/ssh_config
    debug1: /etc/ssh_config line 20: Applying options for *
    debug1: Connecting to github.com [192.30.252.129] port 22.
    debug1: Connection established.
    debug1: identity file /Users/XXXX/.ssh/id_rsa type -1
    debug1: identity file /Users/XXXX/.ssh/id_rsa-cert type -1
    debug1: identity file /Users/XXXX/.ssh/id_dsa type -1
    debug1: identity file /Users/XXXX/.ssh/id_dsa-cert type -1
    debug1: Enabling compatibility mode for protocol 2.0
    debug1: Local version string SSH-2.0-OpenSSH_6.2
    debug1: Remote protocol version 2.0, remote software version libssh-0.6.0
    debug1: no match: libssh-0.6.0
    debug1: SSH2_MSG_KEXINIT sent
    debug1: SSH2_MSG_KEXINIT received
    debug1: kex: server->client aes128-ctr hmac-sha1 none
    debug1: kex: client->server aes128-ctr hmac-sha1 none
    debug1: sending SSH2_MSG_KEXDH_INIT
    debug1: expecting SSH2_MSG_KEXDH_REPLY
    debug1: Server host key: RSA 16:27:ac:a5:76:28:2d:36:63:1b:56:4d:eb:df:a6:48
    debug1: Host 'github.com' is known and matches the RSA host key.
    debug1: Found key in /Users/XXXX/.ssh/known_hosts:1
    debug1: ssh_rsa_verify: signature correct
    debug1: SSH2_MSG_NEWKEYS sent
    debug1: expecting SSH2_MSG_NEWKEYS
    debug1: SSH2_MSG_NEWKEYS received
    debug1: Roaming not allowed by server
    debug1: SSH2_MSG_SERVICE_REQUEST sent
    debug1: SSH2_MSG_SERVICE_ACCEPT received
    debug1: Authentications that can continue: publickey
    debug1: Next authentication method: publickey
    debug1: Trying private key: /Users/XXXX/.ssh/id_rsa
    debug1: Trying private key: /Users/XXXX/.ssh/id_dsa
    debug1: No more authentication methods to try.
    Permission denied (publickey).
    

    Next, eval "$(ssh-agent -s)" returns "Agent pid 2314", however ssh-add -l returns "The agent has no identities."

    And that is where I am stuck.

    • Etan Reisner
      Etan Reisner over 9 years
      Do you have an SSH key created? Do you have it listed with your github account? Do you have the key on your mac?
    • Dark
      Dark over 9 years
      I was looking for the answer to that question (not being familiar with this whole system), and found this: mac.github.com It solved all my problems. I highly recommend it. Thanks for the push in the right direction, Etan!
    • Etan Reisner
      Etan Reisner over 9 years
      You might want to add that an an answer to this question (with further details about how it solved your problem) and accept your answer.
    • Dark
      Dark over 9 years
      Okay, I've submitted the answer. SO is telling me I can only accept it in 2 hours.
  • tuk0z
    tuk0z about 9 years
    Thank you @Doedoe for a link to a nice and short answer. And for those who have keyS (ie multiple Git accounts), you might have to use ssh-add /path/to/keyX for each, especialy if they have non-standard names. Details here: stackoverflow.com/questions/3225862/… (a nice answer)
  • Cthulhu
    Cthulhu about 8 years
    Hi, welcome to SO. Please explain your code, so your fellow users can understand what's going on. Cheers.
  • Louwki
    Louwki over 7 years
    When you reboot your keys are gone and you have to 'ssh-add' them again.
  • jungledev
    jungledev over 7 years
    Thanks for this. I got stuck here.. but I realized that I need to run ssh-add again after resolving the permissions part of the issue. After this, ssh -vT [email protected] did not work. I did need to add the absolute path like the commenter above mentioned. Then, it was all gravy.
  • Kiryl Bielašeŭski
    Kiryl Bielašeŭski over 7 years
    In second case I forgot my passphrase and I've recovered it using help.github.com/articles/how-do-i-recover-my-ssh-key-passphr‌​ase
  • Chris Cirefice
    Chris Cirefice almost 7 years
    Great answer, I was going to mention this myself! Apparently, OS X 10.12.2 and later doesn't automatically load identities into ssh-agent (which I personally think is a really stupid usability decision, but I understand the security implications). So, you need to modify the SSH configuration to load them manually. I just wish the error output would better lead to a solution, rather than an hour of searching the internet.
  • Chris Cirefice
    Chris Cirefice over 6 years
    @Louwki Yeah... that's super annoying. Do you know a way around that?
  • Louwki
    Louwki over 6 years
    @ChrisCirefice just do the ssh-add with a parameter to add them to your keychain permanently. ssh-add -K ~/.ssh/[your-private-key]
  • Robert
    Robert over 5 years
    I don't think the question is about ~/.ssh permissions. Still, you could greatly improve your answer by adding the full command (here chmod) and explaining what this does and why it's needed.
  • davidrynn
    davidrynn about 5 years
    Yup - if you've gone through the other steps of creating the id_rsa.pub file, copy and paste that pbcopy line, which copies the key to your clipboard and follow @zouhair instructions - github needs to know your key. Particularly if you're using 2FA.
  • Mark Löwe
    Mark Löwe about 5 years
    I'm slightly confused because the current docs say git creates github_rsa / github_rsa.pub. I have both in my /.ssh directory and yet I can't seem to "get permission." I've created copies in the same directory using the id_rsa to no avail.
  • Morteza
    Morteza almost 5 years
    In my case, file permissions was wrong for private key. Fixed by chmod 600 ~/.ssh/id_rsa, then ssh-add ~/.ssh/id_rsa
  • lasec0203
    lasec0203 over 3 years
    gotta know the paraphrase or else you'll be creating another private key
  • cooltea
    cooltea over 3 years
    I tried this answer but it seems like a step where the key is added again using ssh-add -K <key> is needed after 2. @ChrisCirefice 's link seems to indicate so.
  • Sara Inés Calderón
    Sara Inés Calderón over 3 years
    thank you! i'd been re-trying this and for whatever reason this worked for me, thanks so much. very easy to read and understand and execute.
  • Hai Feng Kao
    Hai Feng Kao about 3 years
    ssh-add -l doesn't work, but ssh-add works. Why?
  • Timo
    Timo over 2 years
    if you dont want to generate new keySKIP ssh-keygen is misleading better: step needed if no ssh rsa key created. I would add the necessary ssh-agent command to start the agent, otherwise ssh-add will error with Could not open a connection to your authentication agent..
  • Jeff Spicoli
    Jeff Spicoli over 2 years
    I also had to run ssh-add ~/.ssh/id_rsa after
  • Mher Aghabalyan
    Mher Aghabalyan about 2 years
    This works with Amazon Linux server as well
  • Kyusuf Muhammad
    Kyusuf Muhammad about 2 years
    Thank you Boltun Oreh, it's work for me too. @Louwki thank you for the explanation.