Fix – : permission denied (publickey). fatal could not read from remote repository




While trying to clone to a repository, due to the lack of access to your computer's public key GitHub does not trust your computer and rejects your connection. When you attempt to clone the repository, you receive the following error message:


npx degit -m=git path/path my-app


! Command failed: git clone my-app
Cloning into my-app... Permission denied (publickey).
fatal: Could not read from remote repository.

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


Step 1: Generate the SSH key

In the current directory's terminal:


Result A:

Generating public/private rsa key pair.
Enter file in which to save the key (/Users/path/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:

In the above result A:

  • For Enter file in which to save the key we can press enter and continue to save as the default name which is "id_rsa".
  • For Enter passphrase also we can press enter and continue or we can also provide a passphrase which is like a password.

Result B: On successful entry of result A, we are directed with the following output which shows the path of SSH keys.

Your identification has been saved in /Users/path/.ssh/id_rsa
Your public key has been saved in /Users/path/.ssh/
The key fingerprint is:
SHA256:bWzCn***************************** user@*******.local
The key's randomart image is:
+---[RSA 3072]----+
|     ..+o   =*++o|
|   *****    *****|
|     . =.=+++... |
|   *****    *****|
|    . +   O.+o.  |
|   *****    *****|
|       .  .      |

Step 2: Copy the SSH key

cat /Users/path/.ssh/

Copy the SSH Key(contents) from the file.

Step 3: Add the SSH key to GitHub

  • Click on settings in the GitHub Account.
  • Click on `SSH and GPG keys.
  • Click on the NEW SSH key button.
  • Enter the title, paste the key value, and then click on add SSH key.


Now on running your clone or degit command, you should be able to clone to the repository without any issues. With this approach, you need not supply your Username and password to GitHub which is of course a more secure way.

Thank you.