➜ / 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
Github generate new personal access 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!
More Posts related to Git,
- Fix [oh-my-zsh] Cant update: not a git repository
- [fix] fatal: pathspec index.html did not match any files error
- How to ignore files in git using .gitignore file
- Git Fix: fatal: refusing to merge unrelated histories Error
- Install GitHub Command Line Tool on Mac
- How to change directory in Git bash
- Get List of all local branches git command
- fix fatal: --local can only be used inside a git repository error
- [git] fatal: your current branch 'main' does not have any commits yet
- Git Revision Questions Before the Interview
- Change the default git branch name from master to main
- git command to remove/unstage files from staging area
- Remove git config at Local, Global or System Levels?
- [fix] fatal: this operation must be run in a work tree in git
- Clone a particular remote brach using git clone command
- How do I get a list of all branches in Git?
- How to check your installed version of Git
- Step-by-Step: How to delete a git branch from local as well as remote origin
- Git Commit - Author identity unknown, Please tell me who you are email
- fatal: Unable to create '/c/git_repo/.git/index.lock': File exists. If no other git process is currently running, this probably means a git process crashed in this repository earlier.
- How to Rename a Git Local Branch Using the --move Option
- Perform an Empty Commit in Git without anything in Staging Area
- [Fixed] Git Clone git@github.com: Permission denied (publickey) Could not read from remote repository Fatal error
- GitHub: How to Search Code
- Rename git branch on Local and GitHub Remove using Command
More Posts:
- How to install Python 3.9 using brew on Mac - Python
- Fix: Windows 10/11 Update Install Error - 0x80070103 - Windows
- How to create Jira API Token for Atlassian Account to connect Jira Cloud REST API - Jira
- Java SE JDBC Select Statement Example - Java
- Where is .zshrc file located in macOS - MacOS
- Align html element at the center of page vertically and horizontally - Html
- How to detect Browser and Operating System Name and Version using JavaScript - JavaScript
- How to Concatenate Strings in Bash Scripting - Bash