ssh -T [email protected] Permission denied (publickey)

7,521

Solution 1

On OSX, if you type

ssh-add -l

and you get back "no identities", that means your ssh agent does not have any identities loaded into it. Oftentimes, when the mac reboots, you have no identities.

I add mine back after a re-boot by explicitly running

ssh-add

This loads a default identity from ~/.ssh/id_rsa

You can also use the ssh-add command with a specific identity

ssh-add ~/foo/bar/is_rsa

After you add your identies, you can seem them all listed by typing

ssh-add -l

Make sure you have at least one listed.

Solution 2

Follow the commands:


    mkdir ~/.ssh //in case that the folder doesnt exist...
    cd ~/.ssh

    ssh-keygen -t rsa -C "[email protected]"
    #hit enter when asks for file to save the key.
    #enter the passphrase

At last copy the id_rsa.pub into your github account.

Solution 3

Try this in your terminal:

eval `ssh-agent -s`

ssh-add ~/.ssh/id_rsa

enter your passphrase if any and it should work. Hope this helps :-)

Solution 4

I hope this helps you:

I was having the identical problem and about to take my own eyes out with insane frustration; nothing online led me to an answer and I was trying to use the git push command without specifying the URL exactly (which could also solve the problem I believe), so I didn't see how the connection was failing.

I had set up my .ssh/config correctly for two users with two different keys, even using IdentitiesOnly yes which is supposed to override ssh-agent that was automatically supplying the WRONG ssh identity.

I finally realized the problem as I examined the local repository configuration - it was the entry

[remote "origin"]
  url = [email protected]:{my-username}/{my-repo-name}.git

My configuration in .ssh/config file was using the same HostName github.com entry for both users and I'm completely new to all this so I didn't realize that to correctly override ssh-agent, I had to specify the exact URL or else the specific identities in my .ssh/config file would be ignored and the first key that ssy-agent listed (which was the wrong one my my case) would be used by default.

I fixed this by changing the local repo URL to url = git@github-personal:{my-username}/{my-repo-name}.git, where I had set Host github-personal as the identity in my .ssh/config.

Another way to solve this would be specifying the user in the URL in the git push command itself, or even better, a solution described here in a post AFTER solving this my own crappy way:

https://superuser.com/questions/272465/using-multiple-ssh-public-keys

I can't believe that no official source could offer a solution for or even properly explain this edge-case that seems really common (accessing two different github accounts from one machine with SSL).

Share:
7,521

Related videos on Youtube

bordumb
Author by

bordumb

Updated on November 24, 2022

Comments

  • bordumb
    bordumb over 1 year

    I tried to push my blog (Octopress) to github and got this error:

    MacBook-Air:octopress bdeely$ git push origin source
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    Please make sure you have the correct access rights
    and the repository exists.
    

    I generated an SSH key, saved it, and even linked it with my GitHub account in the SSH key settings, but I went ahead and checked the status and got the same error:

    MacBook-Air:.ssh bdeely$ ssh -T [email protected]
    Permission denied (publickey).
    

    In addition to this, I checked github's help page, did the following and got this error message:

    MacBook-Air:~ bdeely$ ssh-add -l
    The agent has no identities.
    

    Does anyone know what is wrong and how I can fix this?

    • Christos Papoulas
      Christos Papoulas over 10 years
      Have you check the permission of the two files in .ssh folder? They must have 600 permisions? How you generate the keys?
  • bordumb
    bordumb over 10 years
    Thanks Christos. I already created SSH keys, as stated above. How would I add 600 permissions?
  • Christos Papoulas
    Christos Papoulas over 10 years
    in linux OS you can with the following way: cd ~/.ssh and chmod 600 id_rsa*
  • Christos Papoulas
    Christos Papoulas over 10 years
    How you copy-paste the id_rsa.pub into github account?
  • Christos Papoulas
    Christos Papoulas over 10 years
    check out this tutorial, if you havent find that already.
  • bordumb
    bordumb over 10 years
    I found my problem... In this section: Enter file in which to save the key (/Users/you/.ssh/id_rsa): I accidentally entered text instead of simply hitting "enter" This would have been an impossible error to find....
  • bordumb
    bordumb over 10 years
    Thanks so much for the help Christos...it was a very bad error on my part.
  • arntg
    arntg about 4 years
    Had a similar issue, just that in my case the issue in .ssh/config was with Host * definition of IdentityFile. Once I commented IdentityFile then ssh -T [email protected] passed. And in my case, I also had IdentitiesOnly yes defined (again under Host *) - but removing it or switching to no made no impact.