A «Permission denied» error means that the server rejected your connection. There could be several reasons why, and the most common examples are explained below.
Should the sudo command or elevated privileges be used with Git?
You should not be using the sudo command or elevated privileges, such as administrator permissions, 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.
Check that you are connecting to the correct server
Typing is hard, we all know it. Pay attention to what you type; you won’t be able to connect to «githib.com» or «guthub.com». In some cases, a corporate network may cause issues resolving the DNS record as well.
To make sure you are connecting to the right domain, you can enter the following command:
$ ssh -vT git@github.com
> OpenSSH_8.1p1, LibreSSL 2.7.3
> debug1: Reading configuration data /Users/YOU/.ssh/config
> debug1: Reading configuration data /etc/ssh/ssh_config
> debug1: /etc/ssh/ssh_config line 47: Applying options for *
> debug1: Connecting to github.com port 22.
The connection should be made on port 22, unless you’re overriding settings to use SSH over HTTPS.
Always use the «git» user
All connections, including those for remote URLs, must be made as the «git» user. If you try to connect with your GitHub username, it will fail:
$ ssh -T GITHUB-USERNAME@github.com
> Permission denied (publickey).
If your connection failed and you’re using a remote URL with your GitHub username, you can change the remote URL to use the «git» user.
You should verify your connection by typing:
$ ssh -T git@github.com
> Hi USERNAME! You've successfully authenticated...
Make sure you have a key that is being used
The ssh-add command should print out a long string of numbers and letters. If it does not print anything, you will need to generate a new SSH key and associate it with GitHub.
Tip: On most systems the default private keys (~/.ssh/id_rsa and ~/.ssh/identity) are automatically added to the SSH authentication agent. You shouldn’t need to run ssh-add path/to/key unless you override the file name when you generate a key.
Getting more details
You can also check that the key is being used by trying to connect to git@github.com:
$ ssh -vT git@github.com
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type -1
> debug1: identity file /Users/YOU/.ssh/id_rsa-cert type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa type -1
> debug1: identity file /Users/YOU/.ssh/id_dsa-cert type -1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Trying private key: /Users/YOU/.ssh/id_rsa
> debug1: Trying private key: /Users/YOU/.ssh/id_dsa
> debug1: No more authentication methods to try.
> Permission denied (publickey).
In that example, we did not have any keys for SSH to use. The «-1» at the end of the «identity file» lines means SSH couldn’t find a file to use. Later on, the «Trying private key» lines also indicate that no file was found. If a file existed, those lines would be «1» and «Offering public key», respectively:
$ ssh -vT git@github.com
> ...
> debug1: identity file /Users/YOU/.ssh/id_rsa type 1
> ...
> debug1: Authentications that can continue: publickey
> debug1: Next authentication method: publickey
> debug1: Offering RSA public key: /Users/YOU/.ssh/id_rsa
Verify the public key is attached to your account
You must provide your public key to GitHub to establish a secure connection.
If you don’t see your public key in GitHub, you’ll need to add your SSH key to GitHub to associate it with your computer.
Warning: If you see an SSH key you’re not familiar with on GitHub, delete it immediately and contact GitHub Support, for further help. An unidentified public key may indicate a possible security concern. For more information, see «Reviewing your SSH keys.»
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
answered Apr 15, 2010 at 7:59
27
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/
answered Dec 22, 2011 at 22:30
Stephan KristynStephan Kristyn
15k14 gold badges88 silver badges147 bronze badges
18
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.
answered May 9, 2013 at 15:14
kavinyaokavinyao
2,9512 gold badges20 silver badges23 bronze badges
5
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
answered Nov 29, 2015 at 15:09
jarorajarora
5,4042 gold badges34 silver badges46 bronze badges
7
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.
answered Apr 11, 2020 at 20:43
crimbocrimbo
10.3k8 gold badges51 silver badges55 bronze badges
10
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. 
answered Jan 3, 2018 at 23:58
Robina LiRobina Li
1,1781 gold badge7 silver badges4 bronze badges
2
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.
- Open Terminal.
- Enter
ls -al ~/.sshto 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
- Open Terminal.
- 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" - 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 toEnter a file in which to save the key (/Users/you/.ssh/id_rsa): [Press enter]Just press enter again. - At the prompt,
"Type a secure passphrase. Enter passphrase (empty for no passphrase): [Type a passphrase]"press enter if you don’t want toEnter 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
-
Interminal type
eval "$(ssh-agent -s)" -
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 -
Now copy the SSH key and also add it to you github account
-
In terminal enter this command with your ssh file name
pbcopy < ~/.ssh/id_rsa.pubThis 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.
answered Mar 7, 2017 at 6:28
Zeeshan ShabbirZeeshan Shabbir
6,7244 gold badges38 silver badges74 bronze badges
7
This works for me:
ssh-add ~/.ssh/id_rsa
answered Jan 7, 2017 at 12:17
2
Visual guide (Windows)
1 of 2. Git batch side
1.1. Open git batch (Download her)
1.2. Paste the text below (Change to your GitHub account email)
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
1.3. Press Enter (Accepts the default file location)
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
SSH and GPG keys => New SSH key:
Paste the code from step 1.6
Done 
If someone doesn’t want to use SSH use HTTPS :
Github docs: https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
answered Jul 21, 2020 at 21:43
Ezra SitonEzra Siton
6,9872 gold badges25 silver badges37 bronze badges
0
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).
answered Oct 25, 2021 at 6:37
wtjwtj
4394 silver badges5 bronze badges
1
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.
answered Jan 17, 2013 at 20:13
Mason BryantMason Bryant
1,37214 silver badges23 bronze badges
1
Please try this if nothing is worked out
- Generate personal Access token (
Setting -> Developer settings -> Personal access tokens -> Generate new token) 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)
answered Dec 20, 2021 at 5:06
1
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,8217 gold badges44 silver badges48 bronze badges
answered Jul 28, 2016 at 3:53
William HuWilliam Hu
15.4k11 gold badges101 silver badges121 bronze badges
3
These are the steps I followed in windows 10
-
Open Git Bash.
-
Generate Public Key:
ssh-keygen -t rsa -b 4096 -C "youremailaddress@xyz.com" -
Copy generated key to the clipboard (works like CTRL+C)
clip < ~/.ssh/id_rsa.pub -
Browser, go to Github => Profile=> Settings => SSH and GPG keys => Add Key
-
Provide the key name and paste clipboard (CTRL+V).
-
Finally, test your connection (Git bash)
ssh -T git@github.com
Thanks!
answered Mar 21, 2020 at 15:12
0
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
answered Dec 17, 2013 at 0:43
RichipalRichipal
7211 gold badge9 silver badges11 bronze badges
2
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
answered Oct 5, 2021 at 7:16
KeshavDulalKeshavDulal
3,12029 silver badges31 bronze badges
I had to copy my ssh keys to the root folder.
Google Cloud Compute Engine running Ubuntu 18.04
sudo cp ~/.ssh/* /root/.ssh/
answered Dec 2, 2019 at 18:56
KandarpKandarp
8937 silver badges8 bronze badges
0
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.
answered May 30, 2014 at 17:37
AndrewAndrew
9,0908 gold badges46 silver badges59 bronze badges
2
Guys this is how it worked for me:
- Open terminal and go to user [See attached image]
- 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
- git —version [Check for git installation and version]
- git config —global user.email «your email id»
- git config —global user.name «your name»
- git config —list [make sure you have set your name & email]
- cd ~/.ssh
- ssh-keygen, it prompts for saving file, allow it
- 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
Fabian Lauer
8,9314 gold badges26 silver badges35 bronze badges
answered May 18, 2016 at 3:40
1
I hit this error because I needed to give my present working directory permissions 700:
chmod -R 700 /home/ec2-user/
answered Jun 29, 2018 at 17:33
duhaimeduhaime
25.7k17 gold badges172 silver badges224 bronze badges
1
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.
answered Nov 7, 2012 at 20:58
JasonJason
3,0301 gold badge23 silver badges25 bronze badges
One of the easiest way
go to terminal-
git push <Git Remote path> --all
answered Nov 6, 2013 at 6:04
VizllxVizllx
9,1451 gold badge41 silver badges79 bronze badges
1
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…
answered May 2, 2012 at 19:36
gMalegMale
17.2k17 gold badges91 silver badges116 bronze badges
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
answered Nov 20, 2016 at 21:28
Nizar B.Nizar B.
3,0989 gold badges38 silver badges56 bronze badges
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 
answered Aug 23, 2016 at 5:42
karthik339karthik339
1991 silver badge6 bronze badges
I deleted node_modules/ package-lock.json and yarn.lock files. Ran npm i again. This resolved the issue for me.
answered Dec 16, 2021 at 11:59
Anupam ChaplotAnupam Chaplot
1,1341 gold badge9 silver badges22 bronze badges
0
If you have more than one key you may need to do
ssh-add private-keyfile
answered Jul 3, 2016 at 0:08
keioskeios
4624 silver badges10 bronze badges
1
The «Permission Denied» error on Github Push occurs when you are trying to push changes to a repository, but you don’t have the necessary permissions to do so. This error usually pops up when you are trying to push changes to a repository that you do not own, or when you are working with a repository that has been made private by the owner. This can be frustrating, especially when you are trying to contribute to an open-source project or collaborate with other team members on a project. In this article, we will look at some methods that you can use to resolve this issue and successfully push your changes to Github.
Method 1: Check Your Github Account Settings
To fix the «Permission denied» error on Github Push, you can check your Github account settings. Here are the steps:
- Open your Github account and go to the repository where you are facing this issue.
- Click on the «Settings» tab on the right side of the screen.
- Scroll down to the «Danger Zone» section and click on «Deploy keys».
- Check if you have added the correct SSH key. If not, click on «Add deploy key» and add the correct key.
- If you have already added the correct key, then check if you have given the correct write access to the key. If not, click on the «Edit» button next to the key and give the correct write access.
Here is an example of adding a deploy key:
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Copy the public key and paste it in the «Key» field while adding the deploy key.
Here is an example of giving write access to the deploy key:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQC2... your_email@example.com
Add «write access» at the end of the key.
That’s it! Now try pushing your changes to Github and it should work without any «Permission denied» error.
Method 2: Check the Repository Permission Settings
If you are experiencing a permission denied error when trying to push to a Github repository, it may be due to incorrect repository permission settings. Here’s how to check and fix it:
Step 1: Check Repository Permission Settings
- Go to your Github repository and click on the
Settingstab. - Click on
Collaborators & teamson the left-hand side menu. - Check if your Github username or team has been added to the list of collaborators or teams with
WriteorAdminaccess. If not, click onAdd collaborator or teamand add yourself with the appropriate access level.
Step 2: Update Local Git Configurations
- Open your terminal or command prompt and navigate to your local repository directory.
- Run the following command to check your Git configurations:
- Look for the
remote.origin.urlconfiguration and ensure that it matches the HTTPS or SSH URL of your Github repository. - If the URL is incorrect, run the following command to update it:
git remote set-url origin <new_url>
Step 3: Push to Github
- Run the following command to push your local changes to Github:
git push origin <branch_name>
- Enter your Github username and password if prompted.
If the permission denied error persists, repeat the above steps to check and update your repository permission settings and Git configurations.
That’s it! By following these steps, you should be able to fix the permission denied error on Github push with repository permission settings.
Method 3: Use SSH Key Authentication
If you are getting a «Permission denied» error when trying to push changes to your Github repository, it may be due to incorrect authentication. One way to fix this is to use SSH Key Authentication. Here are the steps to do it:
-
Check if you have an SSH key already
If you see files named
id_rsaandid_rsa.pub, you already have an SSH key. Skip to step 3. -
Generate an SSH key
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"Press Enter to accept the default file location and enter a passphrase if you want. This will generate a new SSH key.
-
Add your SSH key to Github
Copy the output of this command. Then go to your Github account settings, click on «SSH and GPG keys», and click «New SSH key». Paste the key into the «Key» field and give it a title.
-
Change the remote URL of your repository
git remote set-url origin git@github.com:username/repo.gitReplace
usernameandrepowith your Github username and repository name. -
Test your connection
You should see a message like «Hi username! You’ve successfully authenticated, but Github does not provide shell access.» If you see any errors, double-check your SSH key and Github settings.
That’s it! Now you should be able to push changes to your Github repository without getting a «Permission denied» error.
Method 4: Rebase Your Local Repository
If you are facing a «Permission denied» error on Github push, you can try rebasing your local repository to fix it. Here are the steps to do it:
-
First, make sure you have the latest changes from the remote repository. You can do this by running the following command:
-
Once you have the latest changes, switch to your local branch that you want to push to Github. You can do this by running the following command:
git checkout <your-branch-name> -
Now, rebase your local repository with the latest changes from the remote repository. You can do this by running the following command:
git rebase origin/<your-branch-name> -
If there are any conflicts, resolve them by editing the affected files. Once you have resolved the conflicts, add the changes to the staging area by running the following command:
-
Now, continue the rebase by running the following command:
-
Once the rebase is complete, force push your changes to Github by running the following command:
git push --force-with-leaseNote: The
--force-with-leaseflag is used to avoid overwriting changes that have been made by other contributors.
That’s it! You have successfully fixed the «Permission denied» error on Github push by rebasing your local repository.
If you encounter a «Permission denied» error while pushing to a Github repository, it means that you don’t have the necessary permissions to push changes to the repository. In such cases, you can contact the repository owner to request access.
Here are the steps to do it:
-
Identify the repository owner’s Github username.
-
Navigate to the repository on Github and click on the «Issues» tab.
-
Click on the «New Issue» button.
-
In the issue title, briefly describe the problem as «Requesting write access to [repository name]».
-
In the issue description, provide a detailed explanation of why you need write access to the repository and what changes you intend to make.
-
Tag the repository owner by using the «@» symbol followed by their Github username.
-
Click on the «Submit new issue» button to create the issue.
Here’s an example of what the issue description might look like:
Hi @repositoryowner,
I'm a new developer and I'm interested in contributing to your [repository name] project. However, I'm currently getting a "Permission denied" error when I try to push changes to the repository. I would like to request write access to the repository so that I can contribute to the project.
I plan to make the following changes:
- [list of changes]
Thank you for your time!
Best regards,
[Your name]
Once you’ve submitted the issue, the repository owner will receive a notification and can grant you the necessary permissions to push changes to the repository.
Note: It’s important to provide a detailed explanation of why you need write access and what changes you intend to make. This helps the repository owner understand your intentions and make an informed decision about granting you access.
GitHub isn’t able to authenticate you. So, either you aren’t setup with an SSH key, because you haven’t set one up on your machine, or your key isn’t associated with your GitHub account.
You can also use the HTTPS URL instead of the SSH/git URL to avoid having to deal with SSH keys. This is GitHub’s recommended method.
Further, GitHub has a help page specifically for that error message, and explains in more detail everything you could check.
answered Oct 17, 2012 at 18:15
bdukesbdukes
152k23 gold badges148 silver badges175 bronze badges
16
I know about this problem. After add ssh key, add you ssh key to ssh agent too (from official docs
ssh-agent -s
ssh-add ~/.ssh/id_rsa
After it all work fine, git can view proper key, before couldn’t.
answered Jun 12, 2015 at 14:51
VelikiiNehochuhaVelikiiNehochuha
3,8052 gold badges15 silver badges32 bronze badges
17
Did you create a config file in your ~/.ssh directory? It should have contents like these:
Host github.com
IdentityFile ~/.ssh/github_rsa
Assuming that you created an ssh key named github_rsa
and uploaded it to GitHub…
NOTE: You must follow this way of explicit configuration if you have more than 1 key (2 and more) in your ~/.ssh/ directory. If you don’t specify key this way, then first key in order is taken and used for github authentication, so it depends on the key file name then.
kensai
9439 silver badges16 bronze badges
answered Feb 21, 2014 at 15:43
IgorGanapolskyIgorGanapolsky
26.2k23 gold badges116 silver badges147 bronze badges
10
You need to generate an SSH key (if you don’t have one) and associate the public key with your Github account. See Github’s own documentation.
answered Oct 17, 2012 at 18:13
cdhowiecdhowie
158k24 gold badges289 silver badges302 bronze badges
4
This happened to me. For some reason my origin got messed up without my realizing it:
Check if your settings are still correct
git remote -v
the url needs to be something like ssh://git@github.com/YourDirectory/YourProject.git;
if you don’t see git@github.com, use
git remote set-url origin git://github.com/YourDirectory/YourProject.git
to set it right. Or you could use the github app to check and set the Primary Remote Repository url in the settings panel of your particular repository.
answered May 23, 2013 at 3:30
rmundormundo
7985 silver badges4 bronze badges
2
Issue solved if you change the ssh access to https access to the remote repository:
git remote set-url origin https_link_to_repository
git push -u origin master
answered Nov 13, 2018 at 9:12
george manogeorge mano
5,9486 gold badges33 silver badges43 bronze badges
1
Assuming you are connecting GitHub over SSH, you can run below command to confirm this.
$git config --get remote.origin.url
If you get a result has following format git@github.com:xxx/xxx.github.com.git, then you should do the following.
Generate a SSH key(or use existing one). if you had one, you just need to add your key to the ssh-agent (step 2)and to your GitHub account(step 3).
below are for those who don’t have SSH key.
Step 1 Generating public/private rsa key pair.
$ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
You’ll be asked to confirm where to save the SSH key and what passphrase you want to use.
Step 2 Add your key to the ssh-agent
-
Ensure ssh-agent is enabled
$eval "$(ssh-agent -s)" -
Add your SSH key to the ssh-agent:
$ssh-add ~/.ssh/id_rsa
Step 3 Add your SSH key to your account
$sudo apt-get install xclip
$xclip -sel clip < ~/.ssh/id_rsa.pub
Then add the copied key to GitHub
Go to Settings->SSH keys(Personal settings side bar)->Add SSH key->fill out form(key is on your clipboard, just use ctrl+v)->Add key
After going through above steps, you should solve the permission problem.
Reference Link:
Generating SSH keys.
answered Jan 3, 2016 at 14:34
xinerdxinerd
3913 silver badges7 bronze badges
2
Another solution :
create the SSH keys, type ssh-keygen -t rsa -C "your_email@example.com". This will create both id_rsa and id_rsa.pub files.
Add the id_rsa to ssh list on local computer: ssh-add ~/.ssh/id_rsa.
After generating the keys get the pubkey using :
cat ~/.ssh/id_rsa.pub
you will get something like :
cat ~/.ssh/id_rsa.pub
ssh-rsa AAAB3NzaC1yc2EAAAADAQABAAACAQCvMzmFEUPvaA1AFEBH6zGIF3N6pVE2SJv9V1MHgEwk4C7xovdk7Lr4LDoqEcqxgeJftwWQWWVrWWf7q9qCdHTAanH2Q5vx5nZjLB+B7saksehVOPWDR/MOSpVcr5bwIjf8dc8u5S8h24uBlguGkX+4lFJ+zwhiuwJlhykMvs5py1gD2hy+hvOs1Y17JPWhVVesGV3tlmtbfVolEiv9KShgkk3Hq56fyl+QmPzX1jya4TIC3k55FTzwRWBd+IpblbrGlrIBS6hvpHQpgUs47nSHLEHTn0Xmn6Q== user@email.com
copy this key (value) and go to github.com and under the setting (ssh and pgp key) add your public key.
answered Aug 21, 2017 at 10:09
Badr BellajBadr Bellaj
11.6k2 gold badges43 silver badges44 bronze badges
First, we need to check for existing ssh keys on your computer. Open up Terminal and run:
ls -al ~/.ssh
#or
cd ~/.ssh
ls
and that will lists the files in your .ssh directory
And finally depending on what you see (in my case was):
github_rsa github_rsa.pub known_hosts
Just try setting up your RSA and hopefully that will solve your «git push origin» issues
$ ssh-keygen -lf ~/.ssh/github_rsa.pub
NOTE: RSA certificates are keys-paired so you will have a private and a public certificate, private will not be accessible for you since it belongs to github (in this case) but the public is the one you might be missing when this error happens (at least that was my case, my github account or repo got messed up somehow and i had to «link» the public key, previously generated)
answered Aug 1, 2013 at 23:23
d1jhoni1bd1jhoni1b
7,5371 gold badge51 silver badges37 bronze badges
5
this worked for me:
1- remove all origins
git remote rm origin
(cf. https://www.kernel.org/pub/software/scm/git/docs/git-remote.html)
*remote : «Manage the set of repositories («remotes») whose branches you track.
*rm : «Remove the remote named . All remote-tracking branches and configuration settings for the remote are removed.»
2- check all has been removed :
git remote -v
3- add new origin master
git remote add origin git@github.com:YOUR-GIT/YOUR-REPO.git
that’s all folks!
answered Dec 20, 2017 at 7:22
marcdahanmarcdahan
2,67425 silver badges26 bronze badges
1
If you having issues to make connection with your enterprise Github account then follow the below steps
Solution #1
ERROR: git@github.com: Permission denied (public key). fatal: Could not read
from remote repository. Please make sure you have the correct access
rights
Solution (OSX)
-
Open your terminal and follow below commands
-
$ cd ~
-
$ sudo su
-
$ ssh-keygen
- Enter file in which to save the key (/var/root/.ssh/id_rsa): $ id_rsa
- Enter passphrase (empty for no passphrase): $ hit enter
- Enter same passphrase again: $ hit enter
-
$ cd ~/.ssh
-
$ cat id_rsa.pub
-
copy display content.
-
Open GitHub click your profile icon settings>SSH and GPC Keys
-
Click on the new ssh key button
-
enter any title and key that you copied
-
check now your issue is resolved
Solution #2
ERROR 2: remote: Password authentication is not available for Git operations.
remote: You must use a personal access token or SSH key.
remote: See https://github.compnay.com/settings/tokens or https://github.compnay.com/settings/ssh
fatal: unable to access 'https://github.company.com/repo/app.git/': The requested URL returned an error: 403
Support for password authentication was removed on August 13, 2021. Please use a personal access token instead.
https://namespaceit.com/blog/remote-support-for-password-authentication-was-removed-on-august-13-2021-please-use-a-personal-access-token-instead
answered Nov 19, 2021 at 21:44
Abhishek TomarAbhishek Tomar
8271 gold badge10 silver badges20 bronze badges
3
Yes I too had this question :/ I was going to push my project to Github in HTTP type(not in SSH type). I had to enter my username and password in each push.
So first I entered code relevant to below type
git remote add origin git@github.com:YOUR-GIT/YOUR-REPO.git
and I got
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.
So however I solved my problems by doing below methods
git remote rm originremove your git remote repositorygit remotenow check whether your remote remote repository have been removed
URL =
https://github.com/<username>/<repository>.git
git remote add origin URLAgain add your URL to make remote repositorygit push -u origin master
You can push your content to remote repository. In here as you use «-u» with the command you make a tracking branch and with the help of tracking branch in the remote repository you won’t to tell git what branch you push in the next steps
And here if you use linux git will ask username and password before push the content. And give your relevant credentials.
For prevent to give username and password in each push you have to change git config
For list your git config —
git config --global --list
you will see
user.name=<your_username>
user.email=<your_email>
So you have to add credential.helper attribute to your git config
to this
5.git config --global --add credential.helper store add this to your terminal
Now you can add new item to your files then git add., git commit -m "<message>", git push
And now too there git will request your username and password and that will be the last time. And for next git pushes git won’t request username and password from you 
answered May 29, 2021 at 14:03
DamikaDamika
6422 gold badges8 silver badges17 bronze badges
0
I think i have the best answer for you, your git apps read your id_rsa.pub in root user directory
/home/root/.ssh/id_rsa.pub
That’s why your key in /home/your_username/.ssh/id_rsa.pub can’t be read by git. So you need to create the key in /home/root/.ssh/
$ sudo su
$ ssh-keygen
$ cd ~/.ssh
$ cat id_rsa.pub
Then copy the key in your github account.
It’s worked for me. You can try it.
answered Dec 1, 2015 at 11:16
romanroman
7881 gold badge10 silver badges23 bronze badges
1
Make sure ssh-add -l shows a fingerprint of an SSH key that’s present in the list of SSH keys in your Github account.
If the output is empty, but you know you have a private SSH key that works with your github account, run ssh-add on this key (found in ~/.ssh. It’s named id_rsa by default, so you’ll likely run ssh-add id_rsa).
Else, follow these instructions to generate an SSH key pair .
answered Jun 10, 2014 at 21:07
Rose PerroneRose Perrone
61.7k58 gold badges208 silver badges243 bronze badges
0
In case you are not accessing your own repository, or cloning inside a cloned repository (using some «git submodule… » commands):
In the home directory of your repository:
$ ls -a
1. Open «.gitmodules», and you will find something like this:
[submodule "XXX"]
path = XXX
url = git@github.com:YYY/XXX.git
Change the last line to be the HTTPS of the repository you need to pull:
[submodule "XXX"]
path = XXX
https://github.com/YYY/XXX.git
Save «.gitmodules», and run the command for submodules, and «.git» will be updated.
2. Open «.git», go to «config» file, and you will find something like this:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
ignorecase = true
precomposeunicode = true
[remote "origin"]
url = https://github.com/YYY/XXX.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "XXX"]
url = git@github.com:YYY/XXX.git
Change the last line to be the HTTPS of the repository you need to pull:
url = https://github.com/YYY/XXX.git
So, in this case, the main problem is simply with the url. HTTPS of any repository can be found now on top of the repository page.
answered Jan 26, 2016 at 15:19
N. OsilN. Osil
4947 silver badges13 bronze badges
I was using github earlier for one of my php project. While using github, I was using ssh instead of https. I had my machine set up like that and every time I used to commit and push the code, it would ask me my rsa key password.
After some days, I stopped working on the php project and forgot my rsa password. Recently, I started working on a java project and moved to bitbucket. Since, I had forgotten the password and there is no way to recover it I guess, I decided to use the https(recommended) protocol for the new project and got the same error asked in the question.
How I solved it?
-
Ran this command to tell my git to use https instead of ssh:
git config --global url."https://".insteadOf git:// -
Remove any remote if any
git remote rm origin -
Redo everything from git init to git push and it works!
PS: I also un-installed ssh from my machine during the debug process thinking that, removing it will fix the problem. Yes I know!! 
T J
42.8k13 gold badges83 silver badges138 bronze badges
answered Jan 1, 2016 at 6:23
3AK3AK
1,23315 silver badges22 bronze badges
1
OK there are few solutions to this one, some of them might already been mentioned but just to keep them together:
-
make sure you keys are present, by default another ~/.ssh/ folder, i.e. id.rsa and id.rsa.pub
-
make sure the keys have correct permissions, you can run chmod:
chmod 600 ~/.ssh/id_rsa
chmod 644 ~/.ssh/id_rsa.pub
-
make sure the content of you public key (id_rsa.pub) matches the one uploaded in the remote repository configuration
-
Finally fix the problems with ssh agent:
ssh-add
Some more info: https://itcodehub.blogspot.com/2015/01/ssh-add-problems-with-ssh-agent-and.html
answered Mar 26, 2019 at 20:16
xprophxproph
1,18111 silver badges7 bronze badges
1
I had the same issue recently. This might help if you need a fix immediately, but this needs to be done every time you re-start your system
From terminal, run : ssh-add ~/.ssh/id_rsa
Enter your system password and that should work.
answered Feb 2, 2017 at 15:28
Allow write access for the key (identity) and then click Add key
If on Windows check for more details in Using Github via SSH.
answered Jun 25, 2020 at 18:49
prostiprosti
42.4k14 gold badges186 silver badges152 bronze badges
1
I would like to add some of my findings:
If you are using GitBash, then make sure the SSH key is stored in ~/.ssh/id_rsa.
By Default GitBash searches for ~/.ssh/id_rsaas default path for SSH key.
Even the file name id_rsa matters. If you save your SSH key in another filename or path, it will throw the Permission Denied(publickey)error.
answered Dec 24, 2016 at 10:10
If you have already created an SSH key and are still getting the error it is because you need to give the user permissions to read and write to the folder you are cloning into. To do this, sudo chmod 777 <your_folder_name_here>".
Of course, this is after you have generated an SSH key and you are still getting this error. Hope this helps future users.
Edit
To add on to this use admin in Windows if you’re using the git bash
answered Sep 8, 2016 at 19:52
KevinKevin
1081 silver badge12 bronze badges
3
TLDR:
- make sure you have
writeaccess to the repo (configure it from the repo’ssettings). - make sure the public key is in the
SSH and GPG keysof your github account.
For me, this error usually occurs when I try to clone some repo from a newly installed machine. When receiving a request, github will first check the public key hash. If the public key does not match any user, github will reject this request. This case is common if the machine is new and your ssh key is newly generated.
answered Jan 5, 2022 at 3:16
Han ZhangHan Zhang
3623 silver badges6 bronze badges
4

-
Open terminal as administrator
-
run this command: «ssh-keygen». It generate a ssh key and will show the folder where it has been created. Check my image
-
copy the generated «ssh key»
-
go to your github profile —> settings —> Click SSH and GPH —> Click «»New SSH Key Button» and paste the «ssh key» and finally «clickthe add Button»
answered Dec 15, 2021 at 11:01
coding360coding360
1611 silver badge2 bronze badges
1
In case somebody else needs this. I created an ssh key with a different name like ar-2022-ssh in the user’s .ssh folder. The problem with this is that Checking for existing SSH keys specifies that supported public keys for GitHub are one of the following.
id_rsa.pub
id_ecdsa.pub
id_ed25519.pub
Once I changed my ssh key name to one of those when generating a key, it worked connecting to GitHub
answered Jun 13, 2022 at 12:35
kenshimakenshima
4014 silver badges12 bronze badges
2
I faced the same problem.
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.
You can track these steps if using the linux:
1. Check for existing SSH keys:
ls -al ~//.ssh/
2. Generate a new SSH key:
ssh-keygen -t ed25519 -C "<your_email_address>"
3. Add your SSH key to ssh agent:
eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519
4. Add your public SSH key to your GitHub account:
cat < ~/.ssh/id_ed25519.pub
Now you are able to push again.
answered Jun 11 at 17:14
you can use Https url to login
i guess you are trying to login with ssh url
when you say git push if it as asking only password consider you are connecting through ssh.better you use http url.
answered Jul 30, 2015 at 3:24
Also in ubuntu, even though there was already SSH key entered in settings in BitBucket, I got this problem. The reason was, I was trying the following:
sudo git push origin master
Not sure why, but it got solved by using
git push origin master
No sudo used.
answered Feb 28, 2016 at 10:25
NabinNabin
11.2k8 gold badges64 silver badges98 bronze badges
For me I tried this —
eval "$(ssh-agent -s)"
then I run
ssh-add ~/.ssh/path-to-the-keyfile
and for generating the key you can run
ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
this will generate the pair of keys (Public and private).
you can store this key to github for more read this Adding a new SSH key to your GitHub account
I hope it will help others 
answered Dec 8, 2016 at 10:52
JoomlerJoomler
2,6303 gold badges30 silver badges37 bronze badges
I was having a similar problem to @Batman. However, because I was running this under /usr/local/src/projectname, running without sudo was not an option.
Just add the -E flag to preseve the environment (your ~/.ssh/ path).
$ sudo -E git clone git@your_repo
From man sudo:
-E, —preserve-env
Indicates to the security policy that the user wishes to pre‐
serve their existing environment variables. The security
policy may return an error if the user does not have permis‐
sion to preserve the environment.
answered Feb 24, 2017 at 1:28
justinjustin
6511 gold badge8 silver badges18 bronze badges
Ad
At Career Karma, our mission is to empower users to make confident decisions by providing a trustworthy and free directory of bootcamps and career resources. We believe in transparency and want to ensure that our users are aware of how we generate revenue to support our platform.
Career Karma recieves compensation from our bootcamp partners who are thoroughly vetted before being featured on our website. This commission is reinvested into growing the community to provide coaching at zero cost to their members.
It is important to note that our partnership agreements have no influence on our reviews, recommendations, or the rankings of the programs and services we feature. We remain committed to delivering objective and unbiased information to our users.
In our bootcamp directory, reviews are purely user-generated, based on the experiences and feedback shared by individuals who have attended the bootcamps. We believe that user-generated reviews offer valuable insights and diverse perspectives, helping our users make informed decisions about their educational and career journeys.
Find the right bootcamp for you

X
By continuing you agree to our
Terms of Service and Privacy Policy, and you consent to
receive offers and opportunities from Career Karma by telephone, text message, and email.

















