Why doesn't my SSH key work for connecting to github?

后端 未结 9 1195
-上瘾入骨i
-上瘾入骨i 2021-01-30 02:19

Note: I\'m not a newb, and I\'ve done this a gazillion times, but for some reason today it decided not to work.

I keep getting the Permission denied (publickey).

相关标签:
9条回答
  • 2021-01-30 02:48

    For ssh you need to change the url. Open up the git config file and change the url to

    url = git@github.com:username/repository.git
    
    0 讨论(0)
  • 2021-01-30 02:52

    I was getting some weird line ending issue in Windows when copying the clone address from github.

    Note the extra character before git. It was NOT appearing in my console. It was invisible.

    git clone git@github.com:user/repo.git ./docker
    Cloning into './docker'...
    Warning: Permanently added the RSA host key for IP address '140.82.XXX.X' to the list of known hosts.
    \302\226git@github.com: Permission denied (publickey).
    fatal: Could not read from remote repository.
    

    It took me a while to notice the \302\226 before git in the response. Once I saw that, I backspaced before git@ and made sure there was just a space there and it worked.

    0 讨论(0)
  • 2021-01-30 02:57

    After creating a config file (~/.ssh/config) it worked. This is what I had to put in it:

    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile ~/.ssh/id_rsa
    TCPKeepAlive yes
    IdentitiesOnly yes
    

    Thanks to @VonC for leading me to there in the comments.

    I don't get why I never needed this before though.

    0 讨论(0)
提交回复
热议问题