1053

I'm on Mac Snow Leopard and I just installed git.

I just tried

git clone git@thechaw.com:cakebook.git

but that gives me this error:

Initialized empty Git repository in `/Users/username/Documents/cakebook/.git/`
Permission denied (publickey).
fatal: The remote end hung up unexpectedly

What am I missing?
I've also tried doing ssh-keygen with no passphase but still same error.

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
teepusink
  • 27,444
  • 37
  • 107
  • 147
  • 14
    have you tried to upload the public key that you have generated via ssh-keygen? – Patrick Cornelissen Apr 15 '10 at 07:52
  • My problem was that I tried clone from `sudo` - this is another user with another public key. – Vitaly Zdanevich Jun 09 '15 at 17:24
  • same error. I previously created a public key through github, then generated another key-pair with the `ssh-keygen` utility. Deleting the old public key in personal settings on github and adding my ssh generated id_rsa.pub key to SSH and GPG keys fixed the cloning permission issues. – Tanner Dolby Mar 04 '20 at 08:08
  • If you're running bash screen and have done everything in every available website, there's a high chance you might have logged out from the session you created the screen session. A quick workaround is to restart the screen session: see https://superuser.com/q/180148 – Le Sir Dog Mar 23 '22 at 09:57
  • There's a page in the documentation that offers some guidance - https://docs.github.com/en/authentication/troubleshooting-ssh/error-permission-denied-publickey – Tiago Martins Peres Jun 20 '22 at 12:49

64 Answers64

1242

If the user has not generated a ssh public/private key pair set before

This info is working on theChaw but can be applied to all other git repositories which support SSH pubkey authentications. (See [gitolite][1], gitlab or github for example.)

First start by setting up your own public/private key pair set. This can use either DSA or RSA, so basically any key you setup will work. On most systems you can use ssh-keygen.

  • First you'll want to cd into your .ssh directory. Open up the terminal and run:

cd ~/.ssh && ssh-keygen

  • Next you need to copy this to your clipboard.
  • On OS X run: cat id_rsa.pub | pbcopy
  • On Linux run: cat id_rsa.pub | xclip
  • On Windows (via Cygwin/Git Bash) run: cat id_rsa.pub | clip
  • On Windows (Powershell) run: Get-Content id_rsa.pub | Set-Clipboard (Thx to @orion elenzil)
  • Add your key to your account via the website.
  • Finally setup your .gitconfig.
  • git config --global user.name "bob"
  • git config --global user.email bob@... (don't forget to restart your command line to make sure the config is reloaded)

That's it you should be good to clone and checkout.

Further information can be found at https://help.github.com/articles/generating-ssh-keys (thanks to @Lee Whitney) [1]: https://github.com/sitaramc/gitolite

-

If the user has generated a ssh public/private key pair set before

  • check which key have been authorized on your github or gitlab account settings
  • determine which corresponding private key must be associated from your local computer

eval $(ssh-agent -s)

  • define where the keys are located

ssh-add ~/.ssh/id_rsa

Rufinus
  • 29,200
  • 6
  • 68
  • 84
  • 10
    Ok. This is actually not a git but an ssh synchronization problem. I got the same with Assembla and you link helped me resolving it. Thanks ! – Alexandre Bourlier Jan 11 '12 at 01:18
  • This answer is helpful but this seems more complete and just as easy if you are generating keys from scratch: https://help.github.com/articles/generating-ssh-keys – whitneyland Sep 12 '14 at 15:55
  • 7
    I experienced a problem with the keygen. It is sensitive to the email address in a global env variable. In case you are having this problem, you will want to specify the email address for your github account in the first step: ssh-keygen -t rsa -C "your_email@youremail.com" – melchoir55 Apr 11 '15 at 18:36
  • cat id_rsa.pub | xclip produces error "Error: Can't open display: (null)", alternatively execute command "cat ~/.ssh/id_rsa.pub" to get the public key. – Lin Song Yang Sep 24 '15 at 23:40
  • just use the cat command, und copy the content to your clipboard (CTRL-C) yourself. – Rufinus Sep 25 '15 at 08:37
  • Will ssh-keygen overwrite my existing key? – tommy.carstensen Jul 23 '16 at 09:35
  • Thank you, Sir! I bit the bullet and just did it & it worked! But it seems like a github bug because I have this with one repo; the same repo works fine with a new local clone. The old ssh key is only a few months old and stll valid. Hrrrrmmmm. – n13 Aug 31 '16 at 11:10
  • 83
    If that still doesn't work, you'll need to `ssh-add ~/.ssh/id_rsa`. – Michael Litvin Jan 05 '17 at 19:36
  • @MichaelLitvin And if that still doesn't work, then you need to `ssh-add -K `. This is needed if you have a passphrase and want the macOS KeyChain be used to provide the password automatically. – Adam Hošek Nov 01 '17 at 13:04
  • 2
    Copying using `xclip` on Linux only worked by doing the following `xclip -sel clip < ~/.ssh/id_rsa.pub` which is listed here: https://help.github.com/articles/generating-ssh-keys – Pat Migliaccio Nov 21 '17 at 23:04
  • Shouldn't you add the key to the ssh agent somewhere in there, like they do in the default github instructions you see in any empty repo on GH? – Hack-R May 01 '18 at 13:23
  • These commands only work in the git bash prompt. For windows you most likely will need to be in your c:/users//.ssh directory. and also name your key "is_rsa". – RayLoveless Aug 20 '18 at 19:14
  • its noted in the commands where they work, in the case of windows is clearly states git bash or cygwin. the name of the key does not matter. you should also use `ecdsa` instead of `rsa` – Rufinus Aug 21 '18 at 06:33
  • thanks for your answer. One thing I would like to ask is why do I have to use `ssh-add ~/.ssh/id_rsa` after rebooting the system every time? Is there a work around to this problem? – scipsycho Jun 08 '19 at 12:36
  • On Mac see https://unix.stackexchange.com/questions/140075/ssh-add-is-not-persistent-between-reboots – Rufinus Jun 10 '19 at 19:44
  • After upgrading to mac os 10.15.5 I started having this same issue with github.com. I resolved it with `ssh-add ~/.ssh/id_rsa` – Harry Jun 03 '20 at 17:17
  • what does the line `eval $(ssh-agent -s)` do? – cryanbhu Nov 26 '20 at 07:53
  • Using GitBash as a command prompt helped instead of using Windows Command promt. Thank you – Lizesh Shakya Mar 01 '21 at 08:16
  • Thanks. This worked for me but not on the first try. Even after trying these commands, making sure I have the correct SSH key in both local repo and Github account and restarting Windows terminal, I still got the same error. I closed the Windows terminal and used Git Bash and everything worked as expected. – Saurabh Misra Jun 29 '21 at 16:10
  • 1
    if you're using PowerShell, that 'copy to your clipboard' step can be `cat id_rsa.pub | Set-Clipboard`, or to be even more powershelly, `Get-Content id_rsa.pub | Set-Clipboard`. – orion elenzil Jul 19 '21 at 01:43
  • I don't understand why we have to add the email address? I have another account that is my personal account. I used 2 different email addresses. – Brian Wiley Aug 13 '21 at 21:31
  • @BrianWiley its not needed for the service itself - github and so on know who you are via your key. Git itself wants a email adress an an author name. but you could also use something like <> for example. – Rufinus Aug 14 '21 at 04:01
  • "unable to start ssh-agent service, error :1058" – PascalIv Nov 18 '21 at 09:52
  • @Pascallv - maybe this will help https://stackoverflow.com/questions/52113738/starting-ssh-agent-on-windows-10-fails-unable-to-start-ssh-agent-service-erro – Rufinus Nov 18 '21 at 15:30
  • I try it doesn't work, then I try again with file name "id_rsa" then it's work ! – Samuel Ricky Saputro Nov 16 '22 at 04:00
  • I've been using Unity, and have been trying to install a package via the Package Manager using git - this gave me the error that everyone's been having in the post. This answer SO nearly worked for me! I tried a lot of things, but I believe that in the end, the thing that worked: not setting a password for the SSH that you create. – Gareth Walkom Aug 23 '23 at 22:11
311

More extensive troubleshooting and even automated fixing can be done with:

ssh -vT git@github.com

Alternatively, according to below comments, we could issue:

ssh -vT git@gitlab.com

or substitute gitlab/github with whatever Git Instance your organisation is running.

Source: https://help.github.com/articles/error-permission-denied-publickey/

Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
  • This did a ton of things, and then at the end I noticed 'authenticated successfully', tried `git pull` and it was fine again. – Phil Ricketts Jul 15 '12 at 20:50
  • 2
    My problem had to do with having a different key for my server. Once I used the above command to determine the issue, I fixed the IdentifyFile in my config file and it worked. – Jarie Bolander Sep 23 '15 at 21:39
  • 2
    Showed which key github was trying to use to authenticate. v helpful – cdosborn Nov 26 '15 at 23:44
  • 59
    This doesn't fix anything. I still get the error in OP's question. – IgorGanapolsky Aug 12 '16 at 19:19
  • ssh -vT git@gitlab.com fixed it for me. – Daniel Aug 15 '16 at 16:15
  • 1
    I tried and still get the issue as OP. It read *You've successfully authenticated, but GitHub does not provide shell access* – Nam G VU Sep 27 '16 at 03:34
  • 27
    The command is there to help you troubleshoot the issue, it isn't a magic fix-this-for-me switch. – Stephan Kristyn Feb 16 '17 at 14:28
  • 3
    I can't say this solved anything, but it is a hell of an interesting command and works with GitHub Enterprise as well. – Hack-R May 01 '18 at 13:25
  • 1
    In my case `ssh -vT git@gitlab.com` on Windows showed me that it was looking for an rsa key but I only had a dsa key in my .ssh directory. – K.Nicholas Dec 23 '18 at 23:10
  • 1
    Thank you! By running your provided command, I found my `~/.ssh/config` was modified by some other testing program and wasn't recover back. So I just deleted my `~/.ssh/config` and fix the issue. Cheers! – Jeff Tian Mar 25 '19 at 02:53
  • You've successfully authenticated, but GitHub does not provide shell access. What does that mean? – Ε Г И І И О Oct 17 '19 at 13:50
  • 2
    Make sure you are trying `ssh` to the correct host. For example, I added the public key correctly to my github account but I was on githubenterprise.com instead of github.com, and therefore, `ssh -vT git@.githubenterprise.com` works but `ssh -vT git@github.com` continues to fail. – user3613932 Jan 11 '21 at 01:03
  • 2
    I cannot thank you enough for this magic command. It showed me that ssh was using the wrong ID, even after deleteing all with `ssh-add -D`. – CodeMonkey May 07 '21 at 12:01
  • If `ssh` connects fine, you might want to switch the ssh binary git uses with `git config --global core.sshCommand /usr/bin/ssh` – shuckc Feb 26 '22 at 09:42
  • 1
    debug1: No more authentication methods to try. git@github.com: Permission denied (publickey). – Sarthak Raval Apr 15 '22 at 06:54
  • this should be a comment, not an answer. – sutan Nov 09 '22 at 12:51
  • this help me to find that my error was related to ssh key permissions were too open. I set them to 600 and now it is working – Jorge Wander Santana Ureña Jul 07 '23 at 18:39
  • this is helpfull. i was looking for such command for a long time – Zeeshan Ghazanfar Jul 25 '23 at 07:55
226

This error can happen when you are accessing the SSH URL (Read/Write) instead of Git Read-Only URL but you have no write access to that repo.

Sometimes you just want to clone your own repo, e.g. deploy to a server. In this case you actually only need READ-ONLY access. But since that's your own repo, GitHub may display SSH URL if that's your preference. In this situation, if your remote host's public key is not in your GitHub SSH Keys, your access will be denied, which is expected to happen.

An equivalent case is when you try cloning someone else's repo to which you have no write access with SSH URL.

In a word, if your intent is to clone-only a repo, use HTTPS URL (https://github.com/{user_name}/{project_name}.git) instead of SSH URL (git@github.com:{user_name}/{project_name}.git), which avoids (unnecessary) public key validation.


Update: GitHub is displaying HTTPS as the default protocol now and this move can probably reduce possible misuse of SSH URLs.

kavinyao
  • 2,951
  • 2
  • 20
  • 23
  • With the `https://github.com` git url, it still says `SSL certificate problem: self signed certificate in certificate chain`. `git -c http.sslVerify=false clone ...` seems like a dangerous move. Chrome doesn't give any ssl warnings though. Thoughts? – Jason Kleban Nov 26 '14 at 16:06
  • 1
    @uosɐſ Sorry but I never encountered this problem. Maybe the first thing to do is to try the same command from a different machine and see if the problem persists. – kavinyao Nov 27 '14 at 03:56
  • 1
    This did it for me, too. Thanks. In order to clone my git repo onto my shared hosting account (1and1) I had to use `git clone https://github.com/MyUserName/MyRepo.git` Simply click on the text links beneath the repo URL to the right of the Github page where it says "_You can clone with HTTPS, SSH, or Subversion._". (Click _HTTPS_ to get the link instead of the default _SSH_.) – Oliver Schafeld Jul 29 '15 at 17:43
  • I had this exact same issue; I have (write) access to a public-facing repo with an SSH key but needed read-only access to clone LFS objects. Replacing the ssh address with the HTTPS URL solved my issue. – Professor Nuke Oct 03 '21 at 18:47
  • 2
    I don't understand.. why does SSL URL require both read AND write permissions to clone? – leopoodle Jul 22 '22 at 05:26
174

The github help link helped me sort out this problem. Looks like the ssh key was not added to the ssh-agent. This is what I ended up doing.

Command 1:

Ensure ssh-agent is enabled. The command starts the ssh-agent in the background:

eval "$(ssh-agent -s)"

Command 2:

Add your SSH key to the ssh-agent:

ssh-add ~/.ssh/id_rsa
jarora
  • 5,384
  • 2
  • 34
  • 46
  • 7
    After upgrade to OSx El Capitan to Sierra this worked for me. – Louwki Sep 21 '16 at 08:53
  • This worked for me on Raspberry Pi, where ssh-add has a "-k" flag instead of "-K", apparently. But once I added my deployment key, I was able to successfully clone my repo using its SSH link. – Josh Apr 10 '17 at 20:34
  • 3
    This is the **real solution** and it was copied+pasted to the accepted answer 4 years later (on [Jan 11 ' 19](https://stackoverflow.com/posts/2643584/revisions)), so this deserves all our upvotes! – CPHPython Aug 07 '20 at 10:25
  • https://stackoverflow.com/questions/17846529/could-not-open-a-connection-to-your-authentication-agent. See if you can find something here or just restart your system and see if it works. – jarora Apr 07 '22 at 19:05
  • "Adding the SSH key to the ssh-agent" solved my problem! – Keivan Ipchi Hagh May 20 '22 at 13:10
  • Command 2 works for me. Before doing this, it asks for my passphrase, which I had to enter by hand. When the command is within `npm`, it fails. – Yan King Yin Nov 13 '22 at 20:15
  • Using ssh-add did the trick, no idea why git does not auto add the keys by default. – NelsonGon Jun 06 '23 at 08:43
105

Another possibility on Windows, which is not covered in any of these answers, and is not covered in the git or github docs on troubleshooting:

git may be using a different openssh executable than you think it is.

I was receiving the Permission denied (public key) error when trying to clone or pull from github and ssh.dev.azure.com, and I'd followed all the instructions and verified that my SSH keys were setup correctly (from SSH's standpoint) using ssh -vT git@github.com and ssh -vT git@ssh.dev.azure.com. And was still getting these errors:

git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

I eventually figured out that the problem is that Git for Windows, and Windows, both have their own versions of openssh. This is documented here: https://github.com/desktop/desktop/issues/5641

I was relying on the Windows ssh-agent service to store my ssh key passphrases, so git (with it's separate version of openssh) couldn't read my private keys. I consider it a bug that this error message is used - it's misleading.

The fix was:

git config --global core.sshCommand "'C:\Windows\System32\OpenSSH\ssh.exe'"

Or in your ~/.gitconfig:

[core]
    sshCommand = 'C:\\Windows\\System32\\OpenSSH\\ssh.exe'

Perhaps this will be fixed in git for Windows soon, but this is the 2nd time I've wasted time on this issue.

crimbo
  • 10,308
  • 8
  • 51
  • 55
  • This also resolved it for me. Strange only one of my visual studio solutions, when I utilized Package Manager Console, with `git pull` I'd receive"Permission Denied (publickey)". However, on other Visual Studio solutions (projects of mine), I wouldn't have any problems... This solution makes sense, how the problem originated for only one of my projects is still a bit of a mystery. – Eric Milliot-Martinez Oct 16 '21 at 16:56
  • Or you can modify `C:\Program Files\Git\etc\gitconfig` instead, if you use Cygwin git in parallel and want to leave `~/.gitconfig` as-is. – yurez Nov 04 '21 at 12:48
  • This issue still exists on win11 (at least after upgrade from win10). Thanks for the solution! Docs can't help with it – Trofogol Feb 07 '22 at 09:56
  • 3
    Choose "Use external OpenSSH" instead of the default option "Use bundled OpenSSH" in the installation process. – Ethan Feb 14 '22 at 22:42
  • Another thank-you! I ran into the same issue when updating to Git-2.35.1.2 (from Git-2.31.1), and this resolved it. – Aaron Mar 18 '22 at 03:27
  • Thank goodness you're here! I suspected this may be a problem with some Git misconfiguration using the wrong storage, the same thing happens with GPG for Windows. This solved my issue! – Eldar B. Jun 20 '22 at 21:21
  • Can confirm this is still an issue. I'm not sure why it started suddenly for me and only affected one of my local windows accounts and the other was working fine. Set in my config. Thanks – RoscoeT Oct 21 '22 at 23:04
  • 1
    I was able to run it for mac as well. Just put the right path for ssh in mac. For me it was "/usr/bin/ssh" – Ninja-aman Feb 13 '23 at 17:36
  • 1
    Thank you so much, you saved my day – Christian Jul 28 '23 at 22:38
  • This saved me a world of pain - Thank you – David Aug 24 '23 at 15:20
99

Got the same error report.

Fixed with using the HTTPS instead of the SSH protocol. Since I don't want to set "SSH keys" for a test PC.

Change URL to HTTPS when clone:

git clone https://github.com/USERNAME/REPOSITORY.git

My problem is a little bit different: I have the URL set to SSH when adding an existing local repo to remote, by using:

git remote add origin ssh://github.com/USERNAME/REPOSITORY.git

To fix it, reset the URL to HTTPS:

git remote set-url origin https://github.com/USERNAME/REPOSITORY.git

BTW, you may check your URL using the command:

git remote -v
origin  https://github.com/USERNAME/REPOSITORY.git (fetch)
origin  https://github.com/USERNAME/REPOSITORY.git (push)

Hope this will help some one like me. :D

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
Robina Li
  • 1,158
  • 7
  • 4
  • I did it this way. It was all ok till I wanted to push an amended commit... and it failed. I got stuck, as no new commits could be used because it's protected against such activity. – Mykola Tetiuk Oct 23 '21 at 16:17
  • Thanks! Not sure why my repo was suddenly configured for SSH, I had only ever used HTTPS so I'm glad you proposed this fix. – A__ Dec 05 '21 at 18:10
97

I was struggling with the same problem that's what I did and I was able to clone the repo. I followed this procedure for Mac.

First Step: Checking if we already have the public SSH key.

  1. Open Terminal.
  2. Enter ls -al ~/.ssh to see if existing SSH keys are present:

Check the directory list to see if you already have a public SSH key. Default public is one of the following d_dsa.pub, id_ecdsa.pub, id_ed25519.pub, id_rsa.pub.

If you don't find then go to step 2 otherwise follow step 3

Step 2: Generating public SSH key

  1. Open Terminal.
  2. Enter the following command with a valid email address that you use for github ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. You will see the following in your terminal Generating public/private rsa key pair. When it prompts to"Enter a file in which to save the key," press Enter. This accepts the default file location. When it prompts to Enter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter] Just press enter again.
  4. At the prompt, "Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]" press enter if you don't want to Enter same passphrase again: [Type passphrase again] press enter again

This will generate id_rsa.pub

Step 3: Adding your SSH key to the ssh-agent

  1. Interminal type eval "$(ssh-agent -s)"

  2. Add your SSH key to the ssh-agent. If you are using an existing SSH key rather than generating a new SSH key, you'll need to replace id_rsa in the command with the name of your existing private key file. Enter this command $ ssh-add -K ~/.ssh/id_rsa

  3. Now copy the SSH key and also add it to you github account

  4. In terminal enter this command with your ssh file name pbcopy < ~/.ssh/id_rsa.pub This will copy the file to your clipboard Now open you github account Go to Settings > SSH and GPG keys > New SSH key Enter title and paste the key from clipboard and save it. Voila you're done.

CBowe14
  • 3
  • 2
Zeeshan Shabbir
  • 6,704
  • 4
  • 38
  • 74
  • 6
    Windows user copy via : cat ~/.ssh/id_rsa.pub | clip – Fabii May 23 '17 at 21:03
  • 4
    Finally after reading here and there for an hour, step by step solution....works great. Remember to add your github password as the passphrase in the steps otherwise will have to add manually everytime – Afshin Ghazi Jun 11 '18 at 11:53
  • Great answer. I would also add it was helpful for me to get info on how to change my remote git details -- see this link for details: https://stackoverflow.com/a/63830575/1818235 – Mike Dec 17 '20 at 16:59
  • Thank you! This worked well for me, except: instead of ssh-add -K ~/.ssh/id_rsa I ran ssh-add ~/.ssh/id_rsa The "-K" option prompted for a PIN, which I don't have. – StvnBrkdll Feb 22 '22 at 23:55
  • As of macOS Ventura, ed25519, instead of RSA, will have to be used instead. – Flair Nov 01 '22 at 23:53
  • This was awesome, I had tried many ways but all in wain... but this worked for me – Samiksha Jagtap Dec 10 '22 at 05:33
  • what if the terminal request for A PIN ? What is that for? – gumuruh Jun 05 '23 at 10:40
46

This works for me:

ssh-add ~/.ssh/id_rsa
Wouter Schoofs
  • 966
  • 9
  • 13
35

Visual guide (Windows)

1 of 2. Git batch side

1.1. Open git batch (Download her) enter image description here

1.2. Paste the text below (Change to your GitHub account email)

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

enter image description here

1.3. Press Enter (Accepts the default file location) enter image description here

1.4. Click Enter Twice (Or set SSH key passphrases - Gitbub passphrases docs)

> Enter passphrase (empty for no passphrase): [Type a passphrase]
> Enter same passphrase again: [Type passphrase again]

1.5. The key generate:

Your identification has been saved in /c/Users/user/.ssh/id_rsa...

1.6. Copy the SSH key to your clipboard.

$ clip < ~/.ssh/id_rsa.pub

2 of 2. Github website user side

Under user setting enter image description here

SSH and GPG keys => New SSH key: enter image description here

Paste the code from step 1.6 enter image description here

Done :)

enter image description here


If someone doesn't want to use SSH use HTTPS :

enter image description here

Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh

Ezra Siton
  • 6,887
  • 2
  • 25
  • 37
31

If your problem appears out of the blue recently (the latter half of 2021), it may have been caused by incompatible hash algorithms.

As of this post (Oct 2021), the latest version of Git for windows is 2.33.1 (release note), who has embraced the latest OpenSSH 8.8p1 (release note), who in turn has deprecated SHA-1. Meanwhile, if your remote Git repository still sticks to SHA-1, you'll fail the authentication.

To see whether you could have fallen into this case, check the version of your software by:

ssh -V
git --version

Then you should check the "Potentially-incompatible changes" section of OpenSSH 8.8/8.8p release note.

TL;DR

Solution 1: Enable SHA-1 again by adding this to your ~/.ssh/config file:

Host <remote>
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa

Remember to replace <remote> with the hostname of your remote repository.

Solution 2: Regenerate your key pair using ECDSA or Ed25519, instead of RSA. For example:

ssh-keygen -t ecdsa -C <comment>

Remember to replace <comment> with your own mnemonic phrase. Then, upload the generated public key to your remote repository.


FYI, I encountered this prompt message when accessing Gitee.com, who uses golang.org/x/crypto/ssh on their server and has posted a page on this issue here (in Mandarin).

git@gitee.com: Permission denied (publickey).
wtj
  • 439
  • 4
  • 5
  • I used Solution 2. Now I'm able to access to remote repo. Thanks a lot. That solution works for Git, TrotoiseGit and SourceTree configured to Git ssh instead of embedded one. – Alfira Jan 10 '22 at 20:53
26

Note that (at least for some projects) you must have a github account with an ssh key.

Look at the keys listed in your authentication agent (ssh-add -l)
(if you don't see any, add one of your existing keys with ssh-add /path/to/your/key (eg: ssh-add ~/.ssh/id_rsa))
(if you don't have any keys, first create one. See: http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/internet/node31.html or just google ssh-keygen)

To verify that you have a key associated with your github account:

Go to: https://github.com/settings/ssh

You should see at least one key with a hash key matching one of the hashes you saw when you typed ssh-add -l just a minute ago.

If you don't, add one, then try again.

Mason Bryant
  • 1,372
  • 14
  • 23
  • You know you have this problem if you have been asked to connect with an SSH key (url looks like `git@github.company.com` instead of `https://github.company.com`) but your Github settings don't have an SSH key. Github supplies step-by-step directions at https://docs.github.com/en/github/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent. – Noumenon Feb 06 '21 at 10:22
21

Please try this if nothing is worked out

  1. Generate personal Access token (Setting -> Developer settings -> Personal access tokens -> Generate new token)
  2. git remote set-url origin https://<TOEKN>@github.com/USERNAME/REPOSITORY.git

Note: If a password popup comes, try to enter the token only (try twice)

Gopala Raja Naika
  • 2,321
  • 23
  • 18
  • 1
    This is one of the easiest ways i found to clone a repo. Thank you. git clone https://@github.com/USERNAME/REPOSITORY.git – Abel Tilahun Aug 09 '22 at 21:22
18

I met the same issue because of I was thought the difference between SSH and HTTPS is

https://github.com/USERNAME/REPOSITORY.git

ssh://github.com/USERNAME/REPOSITORY.git

So I changed from HTTPS to SSH just by changing https:// to ssh:// nothing on the end of the url was changed.

But the truth is:

https://github.com/USERNAME/REPOSITORY.git

git@github.com:USERNAME/REPOSITORY.git

Which means I changed ssh://github.com/USERNAME/REPOSITORY.git to git@github.com:USERNAME/REPOSITORY.git it works.

Stupid error but hope helps someone!

Amir
  • 8,821
  • 7
  • 44
  • 48
William Hu
  • 15,423
  • 11
  • 100
  • 121
  • yes, i changed `ssh://github.com/USERNAME/REPOSITORY.git` to `git@github.com:USERNAME/REPOSITORY.git` it works. – William Hu Jul 28 '16 at 04:22
  • I see because i just use `ssh` instead of `https` so i just changed 'https://' to 'ssh://` then i got the error. So change 'ssh://git/../` to 'git@../" : ) Edited my answer. – William Hu Jul 28 '16 at 04:36
  • It works for me. Thank you very much! I tried https and then ssh but it still keeps denying my access until make it your way with "git clone git@github.com:/myusername/myproject.git". – Thach Van Sep 17 '18 at 22:42
18

These are the steps I followed in windows 10

  1. Open Git Bash.

  2. Generate Public Key:

    ssh-keygen -t rsa -b 4096 -C "youremailaddress@xyz.com"
    
  3. Copy generated key to the clipboard (works like CTRL+C)

    clip < ~/.ssh/id_rsa.pub
    
  4. Browser, go to Github => Profile=> Settings => SSH and GPG keys => Add Key

  5. Provide the key name and paste clipboard (CTRL+V).

  6. Finally, test your connection (Git bash)

    ssh -T git@github.com
    

enter image description here

Thanks!

Satishakumar Awati
  • 3,604
  • 1
  • 29
  • 50
13

I had a slight different situation, I was logged on to a remote server and was using git on the server, when I ran any git command I got the same message

   Permission denied (publickey).
   fatal: The remote end hung up unexpectedly

The way I fixed it was by changing the file /etc/ssh_config on my Mac. from

ForwardAgent no 

to

ForwardAgent yes
Richipal
  • 721
  • 1
  • 9
  • 11
  • The error was occurring while trying to fetch gems from github from a VirtualBox VM. Updated my Vagrantfile to use `config.ssh.forward_agent = true`, restarted the VM, and now it works. – Chris Bloom Jan 08 '15 at 15:49
  • 1
    Might not be the best choice in terms of security according to this: https://heipei.github.io/2015/02/26/SSH-Agent-Forwarding-considered-harmful/ – Dad Dec 29 '16 at 05:35
10

Solution using gh i.e. Github's official CLI

gh installation

brew install gh

gh login or authentication via cli

gh auth login

repo clone

gh repo clone <username or orgname>/<repo-name>

Example: gh repo clone keshavdulal/sample-repo

Rant: I too was bashing my head when git clone suddenly decided not to work anymore and I don't have the patience or brainpower to relearn ssh/public keys/cryptography from scratch just to clone a freaking repo I already have access to. Also surprised no one mentioned gh in the answers yet

KeshavDulal
  • 3,060
  • 29
  • 30
10

ALWAYS CHECK GITHUB FOR SSH-KEYS GENERATION PROCEDUR, NOT SOME OUTDATED BLOG

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

There you can see that keys are generated with:

ssh-keygen -t ed25519 -C "your_email@example.com"

So algorithm is ed25519 not rsa or anything else.

Hrvoje
  • 13,566
  • 7
  • 90
  • 104
  • 1
    I used some old RSA Keys which didnt worked out because it has to be ed25519 as you stated. Thanks a lot for this hint. Your command did the trick, using no password. – snukone Apr 13 '22 at 19:03
9

I had to copy my ssh keys to the root folder. Google Cloud Compute Engine running Ubuntu 18.04

sudo cp ~/.ssh/* /root/.ssh/
Kandarp
  • 893
  • 7
  • 8
8

Are you in a corporate environment? Is it possible that your system variables have recently changed? Per this SO answer, ssh keys live at %HOMEDRIVE%%HOMEPATH%\.ssh\id_rsa.pub. So if %HOMEDRIVE% recently changed, git doesn't know where to look for your key, and thus all of the authentication stuff.

Try running ssh -vT git@github.com. Take note of where the identity file is located. For me, that was pointing not to my normal \Users\MyLogin but rather to a network drive, because of a change to environment variables pushed at the network level.

The solution? Since my new %HOMEDRIVE% has the same permissions as my local files, I just moved my .ssh folder there, and called it a day.

Andrew
  • 9,090
  • 8
  • 46
  • 59
8

Guys this is how it worked for me:

  1. Open terminal and go to user [See attached image]
  2. Open .ssh folder and make sure it doesn't have any file like id_rsa or id_rsa.pub otherwise sometimes it wont properly rewrite files
  3. git --version [Check for git installation and version]
  4. git config --global user.email "your email id"
  5. git config --global user.name "your name"
  6. git config --list [make sure you have set your name & email]
  7. cd ~/.ssh
  8. ssh-keygen, it prompts for saving file, allow it
  9. cat ~/.ssh/id_rsa.pub [Access your public key & copy the key to gerrit settings]

Note: You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated

enter image description here

enter image description here

Fabian Lauer
  • 8,891
  • 4
  • 26
  • 35
vikram jeet singh
  • 3,416
  • 2
  • 21
  • 22
7

I hit this error because I needed to give my present working directory permissions 700:

chmod -R 700 /home/ec2-user/
duhaime
  • 25,611
  • 17
  • 169
  • 224
6

On Windows, make sure all your apps agree on HOME. Msys will surprisingly NOT do it for you. I had to set an environment variable because ssh and git couldn't seem to agree on where my .ssh directory was.

Jason
  • 3,021
  • 1
  • 23
  • 25
6

One of the easiest way

go to terminal-

  git push <Git Remote path> --all
Vizllx
  • 9,135
  • 1
  • 41
  • 79
6

I helped the following:

  1. Open Terminal (Git Bash)
  2. Remove all files in directory .ssh or rename and create new .ssh folder.
  3. To follow in the steps of the instructions:
    1. Generating a new SSH key
    2. Adding your SSH key to the ssh-agent

System: Windows 10.

TiiGRUS
  • 85
  • 1
  • 4
5

The basic GIT instructions did not make a reference to the SSH key stuff. Following some of the links above, I found a git help page that explains, step-by-step, exactly how to do this for various operating systems (the link will detect your OS and redirect, accordingly):

http://help.github.com/set-up-git-redirect/

It walks through everything needed for GITHub and also gives detailed explanations such as "why add a passphrase when creating an RSA key." I figured I'd post it, in case it helps someone else...

gMale
  • 17,147
  • 17
  • 91
  • 116
5

The easiest solution to this, when you are trying to push to a repository with a different username is:

 git remote set-url origin https://USERNAME@github.com/USERNAME/PROJECTNAME.git
Nizar B.
  • 3,098
  • 9
  • 38
  • 56
4

Its pretty straight forward. Type the below command

ssh-keygen -t rsa -b 4096 -C "youremailid@yourdomain.com"

Generate the SSH key. Open the file and copy the contents. Go to GitHub setting page , and click on SSH key . Click on Add new SSH key, and paste the contents here. That's it :) You shouldn't see the issue again.

karthik339
  • 199
  • 1
  • 6
4

I deleted node_modules/ package-lock.json and yarn.lock files. Ran npm i again. This resolved the issue for me.

Anupam Chaplot
  • 1,134
  • 1
  • 9
  • 22
3

In addition to Rufinus' reply, the shortcut to copy your ssh key to the clipboard in Windows is:

  • type id_rsa.pub | clip

Refs:

Community
  • 1
  • 1
Jonathan
  • 2,244
  • 1
  • 23
  • 29
3

If you have more than one key you may need to do ssh-add private-keyfile

keios
  • 462
  • 4
  • 10
3

You could begin by doing the following in the terminal:

  1. cd ~/.ssh

  2. Generate an ssh key by running: ssh-keygen -o -t rsa -C "your@email.com"

  3. When prompted to enter where to save the key, enter: cat id_rsa.pub | pbcopy

  4. Enter and confirm your passphrase which will then generate your new key.

  5. Inform github about the key by running: cat ~/.ssh/id_rsa.pub

  6. Copy the output then head over to github to create a new SSH key. Paste the copied content into the text area, give it a befitting title then hit the ADD KEY button.

Now you can go about your operations hassle-free.

folaRin
  • 109
  • 8
3

This is how I was finally able to push to git


For me, I keep on getting

git@github.com: Permission denied 
fatal: Could not read from remote 

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

So after hours of research, I discovered that after generating your ssh key and making your windows agent recognise your key the last thing I did to fix my issue was to update the ssh-key in the git repo for that project.

So you would log in to your git hub account then go to the repo you want to push to then in the settings look for security that's where you can add your ssh key. For me, the key is stored in a .ssh/id_ed123939.pub

Etemire Ewoma
  • 133
  • 1
  • 7
2

I have just experienced this issue while setting my current project, and none of the above solution works. so i tried looking what's really happening on the debug list using the command ssh -vT git@github.com. I notice that my private key filename is not on the list. so renaming the private key filename to 'id_rsa' do the job. hope this could help.

Rhey M.
  • 21
  • 3
2

It worked for me.

Your public key is saved to the id_rsa.pub;file and is the key you upload to your account. You can save this key to the clipboard by running this:

pbcopy < ~/.ssh/id_rsa.pub

  • copy the SSH key to the clipboard, return to the web portal.
  • In the SSH Key field, paste your SSH key.
  • In the Name field, provide a name for the key.
  • save .
2

In my MAC I solved this with:

cp ~/.ssh/github_rsa ~/.ssh/id_rsa

For some reason my git stopped to find the private key in the github_rsa file. This happened in a specific repo. I mean that in other repositories git kept working normally.

I think it's a bug.

I could find this behavior running ssh -vT git@github.com

CelinHC
  • 1,857
  • 2
  • 27
  • 36
2

In MAC, go to Terminal

1) Navigate to Home Directory using command - cd ~

2) cd .ssh && ssh-keygen (For Defaults, click on Enter/Return key for both inputs)

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/username/.ssh/id_rsa):      
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/usernmae/.ssh/id_rsa.

3) After that , Do "ls". you will find id_rsa.pub file.

4) Copy the contents in the id_rsa.pub file (read using the cat command - cat id_rsa.pub)

5) Navigate to BitBucket or any version tool which supports the SSH keys. Paste the contents using the Add Key Option

That's it. Try to commit and push now.

enter image description here

Sireesh Yarlagadda
  • 12,978
  • 3
  • 74
  • 76
2

For me the actual problem is using text editor to copy the SSH public key to clipboard

If you follow docs.github.com and open .pub file in text editor like Notepad++ to copy SSH public key, Then you will be in trouble.

enter image description here

Instead use

cat ~/.ssh/id_***.pub | clip

command to copy

AzarEJ
  • 552
  • 1
  • 5
  • 16
2

I faced this issue today while trying to setup an existing repository in windows using git bash. The problem was when typing the following:

git clone myreposshurl

In gitbash, ctrl+c and ctrl+v doesn't work. While trying to paste the repository url, I did ctrl+v which introduced some unwanted characters. Finally found and solved the issue when I tried and succeeded cloning another repository. Took 1.5 hours to figure out this stupid mistake.

\302\226git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

If you see characters like \302 like above then this could be one possible cause.

Illegal Argument
  • 10,090
  • 2
  • 44
  • 61
1

I was getting a similar Permission denied (publickey) error when trying to run a makefile.

As an alternative to the SSH steps above, you can Install the native GitHub for Mac application.

Click Download GitHub for Mac from - https://help.github.com/articles/set-up-git#platform-mac

Once you complete setup with your git hub account (I also installed the git hub command line tools but unsure if this step is required or not) then I received an email -

[GitHub] A new public key was added to your account

and my error was fixed.

WickedW
  • 2,331
  • 4
  • 24
  • 54
1

I was getting the same error. My problem was mixing in sudo.

I couldn't create the directory I was cloning into automatically without prefixing the git clone command with sudo. When I did that, however, my ssh keys where not being properly referenced.

To fix it, I set permissions via chmod on the parent directory I wanted to contain my clone so I could write to it. Then I ran git clone WITHOUT a sudo prefix. It then worked! I changed the permissions back after that. Done.

BuvinJ
  • 10,221
  • 5
  • 83
  • 96
1

I was getting this error because I generated the ssh keys with the wrong email. I was able to connect using ssh, but not using git. The solution was to regenerate the keys using the main email address of my github account.

Charles Brunet
  • 21,797
  • 24
  • 83
  • 124
1

It worked for me

ssh -i [your id_rsa path] -T github@github.com
Mr陈哲
  • 11
  • 2
1

This strange error, in my case was a symptom of gnome-keyring-daemon incorrectly naming the key to which it required a password.

I follow the steps outlined here, and entered the password via the terminal. The error, aka the confounding GUI interface, was resolved. See: https://askubuntu.com/questions/3045/how-to-disable-gnome-keyring

rivanov
  • 1,214
  • 18
  • 19
1

In my case, I have reinstalled ubuntu and the user name is changed from previous. In this case the the generated ssh key also differs from the previous one.

The issue solved by just copy the current ssh public key, in the repository. The key will be available in your user's /home/.ssh/id_rsa.pub

Sonu
  • 712
  • 9
  • 7
1
$ cd ~
$ cd .ssh
$ chmod 400 id_rsa
539f
  • 21
  • 2
  • 3
    Load key id_rsa: bad permissions Permissions 0755 for id_rsa are too open. It is required that your private key files are NOT accessible by others. – 539f Oct 08 '17 at 07:33
1

Execute the terminal as admin.

If the terminal can't see your .ssh it will return that error.

Raul Barros
  • 117
  • 1
  • 1
  • 7
1

After did ssh-keygen part, you might check verification by below:

  1. $ ssh -T git@github.com for testing your SSH connection;

  2. Confirm which user ran "ssh-keygen" command. The public key you generated is followed by that user. The reason in below:

Should the sudo command be used with Git?

You should not be using the sudo command with Git. If you have a very good reason you must use sudo, then ensure you are using it with every command (it's probably just better to use su to get a shell as root at that point). If you generate SSH keys without sudo and then try to use a command like sudo git push, you won't be using the same keys that you generated.

  1. Confirm you have write permission for the dir that repository will clone to. If not then do it. And you must refresh current user by logout or su etc after updating user group permission.
Fanco
  • 54
  • 3
0

Use the ssh link from Github but make sure to not append it with ssh just use what the ssh tab on git hub gives you to clone your repo.

pal4life
  • 3,210
  • 5
  • 36
  • 57
0

I was able to get over this issue by following below steps in my ubuntu system. As i was experimenting with passwordless ssh to the system.

sudo vi /etc/ssh/sshd_config

1) Commented below : #Change to no to disable tunnelled clear text passwords #PasswordAuthentication yes PasswordAuthentication no ----> commented this.

2) Then restarted the sshd daemon as below.

service sshd restart

lambzee
  • 100
  • 2
0

Steps for Mac:

  1. Switch user ( sudo su - jenkins)
  2. Generate key ( ssh-keygen -t rsa -b 4096 -C "username") . Username is one with which you are using with jenkins.
  3. Copy generated public key (cat ~/.ssh/id_rsa.pub).
  4. Paste the key to git account. (Settings -> SSH and CPG keys -> New ssh keys -> Enter name of the key (can be any) and paste the key to description).
0

Let me share my experience too,

I was trying to clone some project from the Gerrit repo where I got my public keys in account settings.

On the first attempt to make git clone I got the following error:

Unable to negotiate with XX.XX.XX.XX port XXX: no matching key exchange
method found. Their offer: diffie-hellman-group1-sha1

I figured out that I need to pass the SSH option -oKexAlgorithms=+diffie-hellman-group1-sha1 somehow to git clone.

Hopefully GIT_SSH_COMMAND environment variable did the job:

export GIT_SSH_COMMAND="ssh -oKexAlgorithms=+diffie-hellman-group1-sha1"

But git clone still didn't start to work.. Now it throws the (on topic):

Permission denied (publickey).

I got already SSH keys and didn't want to regenerate them. I checked plain SSH connection to the host and it was ok:

****    Welcome to Gerrit Code Review    ****

  Hi XXXXX, you have successfully connected over SSH.

  Unfortunately, interactive shells are disabled.
  To clone a hosted Git repository, use:

  git clone ssh://xxxxx@xx.xx.xx:xxx/REPOSITORY_NAME.git

I was confused a bit. I started again and turned on the debug for SSH via -vvv option. And I saw the following:

debug1: read_passphrase: can't open /dev/tty: No such device or address

Possibly, it was an overhead for the GIT_SSH_COMMAND env variable - my key was secured with passphrase (and I entered it when I was checking the login to the git repo host).

So, I decided to get rid of the phasphrase then. A simple command helped me:

ssh-keygen -p

Then I entered my passphrase for the "old passphrase" and just hit ENTER twice on the "new passphare" to leave it empty i.e. with no passphrase at all and to confirm my choice.

After that I got the freshly cloned repo on my local disk.

rook
  • 5,880
  • 4
  • 39
  • 51
0

First of all, I recommend checking some standard things like:

  • login as the correct user in your system,
  • have the right private key in the right location in your system,
  • try to connect with the correct username, hostname, and port,
  • have the public key in the right location (and for the right user) in the external server,
  • restarted the ssh service at your computer:
service ssh restart

(or in another way depending on how you manage services in your system...)

It was enough for me.

simhumileco
  • 31,877
  • 16
  • 137
  • 115
  • What is wrong with this answer? Why somebody gives me -1 vote? Maybe I can improve it, if I will know what is wrong with this current one? Please help me smebody, who know what could be wrong. Thank you in advance. – simhumileco Jan 23 '20 at 17:53
  • `$ service ssh restart` bash: service: command not found – GirkovArpa Nov 12 '20 at 10:22
  • Hi @GirkovArpa, maybe this will help: https://www.linuxquestions.org/questions/linux-newbie-8/restart-services-%27service%27-command-not-found-88809/ – simhumileco Nov 13 '20 at 12:13
0

I also had the exact same error.

The problem was that when copying the public key into BitBucket (in my case), a non-visible newline at the end was copy/pasted.

So when copying the public key, first copy it to notepad, remove the empty line at the end, copy it, and paste it.

Michel Keijzers
  • 15,025
  • 28
  • 93
  • 119
0

Possible that public/private config is incorrect. please follow the steps to do it. execute command anywhere in window

ssh-keygen -o -f ~/.ssh/id_rsa

now go to the c://users/xyz/.ssh/ and open the id_rsa key (path can vary) now go to the gitlab and userprofile> setting>ssh keys and add your key here. now try clone

arjun kumar
  • 467
  • 5
  • 12
0

For me the problem was using sudo:

sudo git clone git@github.com:userName/repo.git was resulting in the error mentioned above.

So to fix this I chown the folder I was trying to clone into

sudo chown -R $USER:$USER /var/www/iqge.org/html

then using this git clone git@github.com:userName/repo.git was successfully done

Black Mamba
  • 13,632
  • 6
  • 82
  • 105
0

When ever I get a new computer at work or switch jobs these are steps I follow setup github access. Mac or Windows

-Go to https://github.[yourWorkDomain].com. navigate to Settings → Developer Settings → Personal access tokens
-Generate a new token
-Set the token description and only check the “repo” box for scope (this will give you repo:status, repo_deployment, public_repo, repo:invite access)

-After your are given the token, copy it (don't navigate away yet, confirm the next two steps work)
-Try to clone the repo again(using “https”)
-For the username use your Username
-For the password, paste the token you copied
-All future requests should work now without asking for your username and password.

RayLoveless
  • 19,880
  • 21
  • 76
  • 94
0
  • Make a new folder Anywhere in your PC (ex. on desktop)

  • Move to that new folder and open git bash there.

& Write Following Code there in bash:

$ git init
$ git remote add origin https://github.com/YOUR_GITHUB_HANDLER/YOUR_REPO_NAME.git
$ git pull origin master

(See that new folder whether files are pulled or not)

If files are pulled, then first Delete all files/folders from that older folder (where the described error occurs) including .git folder

& Copy all files from new folder including .git and paste it to our older folder where the described error occurs.

This will fetch you remote repo.

If you want to fetch remote repo without removing new changes which you have made locally, then only copy & paste our new .git folder

Now you will able to do $ git push origin master

ngandhi_369
  • 377
  • 2
  • 8
0

SourceTree for Windows case

In case you use SourceTree on Windows you need to create a new keypair using PuTTyGen

enter image description here

The ssh-rsa key from the top section you should insert to

Github => Profile=> Settings => SSH and GPG keys => Add Key

Then save the private key and add it to Pageant (it runs with the SourceTree)

enter image description here

That's all

kkost
  • 3,640
  • 5
  • 41
  • 72
0

I already authenticated with gh, created the new keys, and so on. The problem was that I installed gh with snap in Ubuntu, so the new key generated was in ./snap/gh/502/.ssh/ instead of the regular .ssh path.

I solved it copying everything to .ssh folder with:

cp -a ./snap/gh/502/.ssh/* .ssh/

If not, find your keys with find . -name *.pub

It's still a problem in the digital world to know where you left your keys, I guess.

ofou
  • 311
  • 2
  • 10
0

wouter schoofs solution helped me with the solution

Tried explaining the same steps by steps

Step 1:

create a new ssh key:-

ssh-keygen -t ed25519 -C "your_email@example.com"

Step 2:

copy the ssh key on clipboard :-

pbcopy < ~/.ssh/id_ed25519.pub 

Step 3:

now paste copied ssh key to the corresponding git repository

Step 4: Start the ssh-agent in the background.

$ eval "$(ssh-agent -s)"
> Agent pid 59566

Step 5: now try accesing the repo

git clone git@github.com:username/repo-name.git

Step 6:

if still you see the issue then check the ssh config file

vim ~/.ssh/config

the content should look like

Host github.com
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

Step 7:

Add your SSH private key to the ssh-agent and store your passphrase in the keychain

ssh-add --apple-use-keychain ~/.ssh/id_ed25519

Step 8:

Now try again it should work

git clone git@github.com:username/repo-name.git
officialrahulmandal
  • 2,473
  • 1
  • 23
  • 31
-1

Adding RSA key in GitHub using terminal:

MAC:

  1. go to folder Users/ xxxx /.ssh
  2. Run command: cd ~/.ssh && ssh-keygen -t ed25519 -C "github_email@id.com"
  3. enter file name as id_rsa
  4. enter if ask passphrase
  5. again enter
  6. Run command eval "$(ssh-agent -s)"
  7. Open config file: open ~/.ssh/config if not exist then create as: touch ~/.ssh/config
  8. Now open config file and add below lines in file:

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

  1. close the file

  2. Add ssh private key to agent run command: ssh-add -K ~/.ssh/id_rsa

  3. Now copy ssh key as: pbcopy < ~/.ssh/id_rsa.pub

  4. Go to gitHub/BitBucket

  5. Click to Manage accounts

  6. Click on SSH key

  7. Delete existing key

  8. Click add key

  9. Paste the copied key.

-1

If you want to use the Https:

The way I was able to fix this issue for me was using the "Caching Your GitHub credentials in git

In the command line, enter { gh auth login }, then follow the prompts

you can refer to the documents with in GitHub

https://docs.github.com/en/get-started/getting-started-with-git/caching-your-github-credentials-in-git

-1

In my case I had to add

PubkeyAcceptedAlgorithms ecdsa-sha2-nistp256,ecdsa-sha2-nistp256-cert-v01@openssh.com,sk-ecdsa-sha2-nistp256@openssh.com,sk-ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2
-nistp521,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-ed25519,ssh-ed25519-cert-v01@openssh.com,sk-ssh-ed25519@openssh.com,sk-ssh-ed25519-cert-v01@openssh.com,rsa-sha2-256,rsa-sha2-256-cert-v01@openssh.com,rsa-sha2-512,rsa-sha2-512-cert
-v01@openssh.com

To file /etc/ssh/ssh_config.d/ciphers.conf

Solved by ssh -vT git@github.com showing error Skipping ssh-ed25519 key ~/.ssh/id_ed25519 - corresponding algo not in PubkeyAcceptedAlgorithms

Scholtz
  • 2,878
  • 2
  • 23
  • 23
-1

For those of you who using Xcode

  • Go to settings -> Accounts
  • Add your Git/gitlab/bitbucket account if wasn't already
  • Select it on left side and go to "SSH Key" section
  • Choose "Create new..." option
  • Key type ED25519 + your passphrase
  • Push something using Xcode
  • Enjoy
Ivan Besarab
  • 990
  • 7
  • 12