➜ / git clone git@github.com:github-username/repo.git
Cloning into 'c2c-2022'...
The authenticity of host 'github.com (13.234.176.102)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wxyV6TuJJhbpZisF/zLDA0zX2A4KZJHY2.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (ED25519) to the list of known hosts.
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.
Fix: Solution 1
The most common reason is you are trying to clone the GitHub repo locally and you have not set the access tocken
Steps to set github access token
- Click on your profile icon on github.com,
- Now click on Settings,
- Scroll down and select Developer settings from the left side menu options,
- Now click on Personal access tokens,
- Now click on the button Generate new token
- You will be prompted to enter your github.com password again,
- Now you will need to add a note to tell what the token will be used for (this token acts like an OAuth token and can be used for API authentication using basic auth. You can also set the expiration for the token from 7 days to 30 days or never expire.
- Now you can select the scope of the token, I have set repo: "Full control of private repositories"
- Now click on Generate Token button
- You should be able to see your token now, copy it.
Do make sure to copy your personal access token on the page as you will not be able to see it again!
% git clone https://<Personal-token>@github.com/<user-name>/<repo-name>.git
Cloning into 'git-repo'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 3 (delta 0), reused 0 (delta 0), pack-reused 0
Receiving objects: 100% (3/3), done.
Fix: Solution 2
The better way is to generate an SSH key locally and add it to the GitHub Settings,
- Open local terminal and run the below command with the email setup with your GitHub account,
ssh-keygen -t ed25519 -C "name@domain.com" Generating public/private ed25519 key pair. Enter file in which to save the key (/root/.ssh/id_ed25519): githubkey Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in githubkey Your public key has been saved in githubkey.pub The key fingerprint is: SHA256:uxABXYZOK4grihAz7B3Afhv3/tanAb7axtjh2BRo4H+Y name@domain.com The key's randomart image is: +--[ED25519 256]--+ |.o.o++.o .. | |o.o+oo= . o. | |+o. +o. .o. . | |+. o.. . ..E | | .. .S o . ... | | . + + ... | | o .. o.. | | . oBoo. | | ..ooB= | +----[SHA256]-----+
- Add the SH key to the ssh-agent:
% eval "$(ssh-agent -s)" % ssh-add ~/.ssh/githubkey
- Now add the ssh key to your GitHub account: cat ~/.ssh/githubkey.pub copy the text,
- Go to GitHub.com account, click on your profile picture and select Settings,
- Now click on SSH and GPG keys,
- Click on button New SSH key
- Add the copied .pub file content into key text area.
- Click Add SSH key
Facing issues? Have Questions? Post them here! I am happy to answer!
Author Info:
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
More Posts related to Git,
- Change the default git branch name from master to main
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- [Solution] fatal: not a git repository (or any of the parent directories): .git
- [fix] zsh: command not found: git
- How to Install Git on Windows
- Setup Git + Visual Studio Code Tutorial
- How to undo last Git Commit on Local Repository?
- Install GitHub Command Line Tool on Mac
- How to Create a Git Branch in 6 Different ways
- Fix Git: Warning: could not find UI helper GitHub.UI on Windows
- Git Config Command - A Deep Dive
- Step-by-Step: How to delete a git branch from local as well as remote origin
- How to Add Git Bash Option to Windows Terminal List
- Command to Clone Repository Using Git Bash
- How to remove or unstage a file from git staged area
- Get the file location of git config values
- GitHub: How to Search Code
- How to check your installed version of Git
- Fix: error: src refspec master does not match any failed to push some refs to Git
- Git: Step-by-Step - How to Push Local Brach to GitHub
- How to Merge Branch into Master Branch
- fix fatal: --local can only be used inside a git repository error
- Fix: Git Pull Error: unable to resolve reference refs/remotes/origin/master: reference broken
- Change the default diff or commit editor for git
- Git Fix: fatal: refusing to merge unrelated histories Error
More Posts:
- Where is AWS Config and Credential files located on Mac - AWS
- Eclipse Error : The Eclipse executable launcher was unable to locate its companion shared library. - Eclipse
- Create SharePoint list from Excel spreadsheet and import table - SharePoint
- How to make EditText text to uppercase or lowercase on macOS - MacOS
- Turn off Startup Sound on Mac running on macOS Ventura - MacOS
- Fix: bash: 127: command not found - Bash
- Downloading Google Chrome using cURL Command - cURL
- How to exclude results from SharePoint Search - SharePoint