Permission denied publickey github windows

GitHub: Permission denied (publickey). fatal: Could not read from remote repository

I´m having trouble with GitHub. I´ve playing around with a remote repository of Git.

When I now try to make any changes to the remote directory, i.e.

I get this error

Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists. Ulrichs-MacBook-Pro:coredatatest ulrichheinelt$ git push -u origin master Permission denied (publickey). fatal: Could not read from remote repository.

I would be happy, when I could start again with a new (empty) remote directory. Or is there a way, to fix this error?

This are my first steps with GitHub, started yesterday. Many thanks in advance!

Edit 1

Edit 2

too early happy 🙁

After setting the SSH and GPG keys, the errors are still the same. :-/

Edit 3

I think that’s right so, but still the same.

10 Answers 10

  • On your GitHub profile there is an Edit Profile button.
    It is located on top-right corner of the webpage.
  • Press it and you will see left Personal Settings menu.
  • Inside that menu find SSH and GPG keys option and press it.
  • You will see an option New SSH key to add new key.

  1. Generate SSH key using ssh-keygen -t rsa -b 4096 -C «your email» .
  2. Copy the output of cat

/.ssh/id_rsa.pub to your clipboard

  • Paste the above copied output to the form at https://github.com/settings/ssh/new
  • generate your key

    Visualize your keys

    Start the agent

    Add your key to the agent

    I was having the same problem with my ssh connection. I tried to work it through ssh, but couldn’t find a working solution for it. So, in that case, I changed my remote URL from SSH to HTTPS. I used the command: $ git remote set-url origin https://github.com/USERNAME/REPOSITORY.git . You can see your remote url changed using: $ git remote -v .

    You can find more detail on Here

    This will change your remote URL to HTTPS so you will now have to type your GitHub username and password to push your project to the remote repo. I know ssh is easier than HTTPS meaning that you don’t have to type out your username and password, but this might be helpful if you didn’t find any solution for fixing it through ssh, and you are in a rush to push your code to your repo.

    permission denied (publickey) Error using git on windows 7

    When I want to push to github with this command

    15 Answers 15

    EUREKA!

    Apparently, you can use plink as the main ssh client and just load your keys in pageant (if you’re like me, you already do):

    You can do that by setting the GIT_SSH env variable to plink.exe path like so:

    set GIT_SSH=C:\Program Files\PuTTY\plink.exe

    or, you can use plink from TortoiseGit:

    set GIT_SSH=c:\Program Files\TortoiseGit\bin\TortoisePLink.exe

    Credit: Original solution taken from this blog post

    I was able to resolve this issue as follows:

    it prompts you to (optionally) enter a filename for saving the generated keys. Specifying a filename wasted my whole day! Next day I let it use the default filename and the problem(s) disappeared! Imagine!!

    Platform was Win7 and msysgit.

    /.ssh/customname (replacing customname with the name of your key, without .pub ). This doesn’t appear necessary in a Linux environment. – matb33 Jun 20 ’12 at 14:28

    Here is a step-by-step guide that I used to get this to work.

    Platform: Windows 7

    During installation, accept all of the default options, except when the ‘Select Components’ option appears. When this appears, select ‘Git Bash Here’ option. Although this isn’t necessary, it adds a nice context menu when working in Windows Explorer that I found to be very helpful.

    Once msysgit is installed Git Bash will also be installed. Open Git Bash in one of 2 ways:

    • Click the Windows Start key and start typing Git Bash
    • Or, right click somewhere (e.g. your Desktop) and select Git Bash Here. This option is only available if ‘Git Bash Here’ context menu was installed.

    In Git Bash’s command window, enter this:

    When asked to enter a file name, just accept the default. Choose a strong passphrase when prompted, and your public key should now be saved. Your screen should look like this:

    Читайте также:  Команда grep windows что такое

    Go open the public key file in Notepad. The file should reside here:

    Copy all of the content in the file to your clipboard, then go to GitHub’s SSH settings page:

    Choose ‘Add SSH key’, enter a useful ‘Title’ and paste the content into the ‘Key’ textarea.

    To simplify your life, you can use the SSH agent to save your passphrase so that you don’t need to remember it. To do so, type this into Git Bash:

    You’ll be prompted to enter your passsphrase. If everything succeeds, your identity will have been added. Note: this passphrase will be forgotten as soon as you close your shell. I’m not sure how to make this persist across sessions, but maybe someone can help?

    To test that everything works, enter this into Git Bash:

    How to solve Permission denied (publickey) error when using Git?

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

    but that gives me this error:

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

    45 Answers 45

    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, 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:

    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) —

    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/id_rsa . – Michael Litvin Jan 5 ’17 at 19:36

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

    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//.git ) instead of SSH URL ( git@github.com:/.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.

    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.

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

    Add your SSH key to the ssh-agent:

    Got same error report.

    Fixed with using HTTP instead. Since I don’t want set «SSH keys» for a test PC.

    Change URL to HTTP when clone:

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

    To fix it, reset URL to HTTP:

    BTW, you may check your URL using command:

    Hope this will help some one like me. 😀

    I was struggling with same problem that’s what i did and i was able clone the repo. I followed these procedure for iMac.

    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 listing to see if you already have a public SSH key.Default public are 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 followong command with you valid email address that you use for github ssh-keygen -t rsa -b 4096 -C «your_email@example.com»
    3. You will see following in 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. At the prompt, type a secure passphrase.
    4. 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

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

    1. In terminal enter this command with your ssh file name pbcopy 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.

    Getting permission denied (public key) on gitlab

    My problem is that I can’t push or fetch from GitLab. However, I can clone (via HTTP or via SSH). I get this error when I try to push :

    Permission denied (publickey) fatal : Could not read from remote repository

    From all the threads I’ve looked, here is what I have done :

    • Set up an SSH key on my computer and added the public key to GitLab
    • Done the config —global for username and email
    • Cloned via SSH and via HTTP to check if it would resolve the issue
    • Done the ssh -T git@gitlab.com command

    If you have any insight about how to resolve my issue, it would be greatly appreciated.

    /.ssh/id_rsa – rivanov Jun 21 ’17 at 20:18

    /.ssh/the_key» followed by authorising they key by phrase. This is the private part of what I added to GitLab. – Celdor Sep 24 ’19 at 12:23

    37 Answers 37

    I found this after searching a lot. It will work perfectly fine for me.

    1. Go to «Git Bash» just like cmd. Right click and «Run as Administrator».
    2. Type ssh-keygen
    3. Press enter.
    4. It will ask you to save the key to the specific directory.
    5. Press enter. It will prompt you to type password or enter without password.
    6. The public key will be created to the specific directory.
    7. Now go to the directory and open .ssh folder.
    8. You’ll see a file id_rsa.pub . Open it on notepad. Copy all text from it.
    9. Go to https://gitlab.com/profile/keys .
    10. Paste here in the «key» textfield.
    11. Now click on the «Title» below. It will automatically get filled.
    12. Then click «Add key».

    Now give it a shot and it will work for sure.

    /.ssh/id_rsa.pub on git bash it will show you the «Key» , so you could copy and paste it to text field in gitlab.com/profile/keys – Chutipong Roobklom Sep 10 ’18 at 3:41

    Step 1: Added a config file in

    /.ssh/config file which looks like

    I think the simple solution is to add private key to authentication agent (if your key is not

    You basically let the ssh-agent take care of it.

    In my case it did not work in the WSL (Windows Subsystem for Linux).

    When I start the WSL, I must

    • start ssh-agent_ eval $(ssh-agent -s)
    • add the key to the ssh-agent: ssh-add

    /.ssh/id_rsa

  • if prompted, enter the password
  • Now the connection works.
    We can test this with ssh -T git@github.com

    • weasel-pageant allows us to reuse the ssh keys that are loaded in PuTTY pageant inside the WSL
    • detailed explanation: Git via SSH from Windows returns Permission Denied

    make sure you are not running sudo git clone git@gitlab.com:project/somethiing.git , otherwise ssh will look in /root/.ssh instead of the key you uploaded

    There is a very simple solution to this: instead of working with ssh — move to https. to do this: in your project folder you have a .git folder in there — you have a config file — open it in a text editor and change the line

    if you are in Linux or macox , just try this in terminal:

    if it return nothing, try this:

    it must create identity in

    it must return your identity, so after retry to clone, it’s must work

    NB: don’t forget to add your ssh key in your profile gitlab

    In my case, it wasn’t a gitlab problem, but a sshd configuration one. The ssh server didn’t allow connection except for a list of users. The user git, the one connecting remotely to gitlab, wasn’t in that list. So, check this before anything else.

    You can check your ssh server configuration in /etc/ssh/sshd_config . If you have a line with the option AllowUsers , add git to it:

    I have gitlab running with docker, this is what I did to fix my problem.

    Found that inside docker /var/log/gitlab/sshd/current there were multiple occurences of a message:

    Authentication refused: bad ownership or modes for file /var/opt/gitlab/.ssh/authorized_keys

    After which I changed ownership of that file from 99:users to git:users with:

    Steps to be done, got same error but i fixed it. Gitlab wants ssh-rsa so below is the code to run ssh for rsa

    1. ssh-keygen -o -t rsa -b 4096 -C «name@gmail.com»

    name@gmail.com is your gitlab account email

    It will prompt you to enter so just hit Enter after the below code is prompt,

    Enter file in which to save the key (/home/yourDesktopName/.ssh/id_rsa):

    It will prompt again you to enter so just hit Enter after the below code is prompt,

    Enter passphrase (empty for no passphrase):

    It will prompt again for the last you to enter so just hit Enter after the below code is prompt,

    Enter same passphrase again:

    You will show your ssh-rsa generate.

    Login to your Gitlab account and Go to the right navbar you will get setting and in the left sidebar you will get ssh key. Enter in it.

    Look above the prompt asking you to enter, you will get the path of ssh-rsa.

    Go to your SSH folder and get the id_rsa.pub

    Open it and get the key and Copy Paste to the Gitlab and you are nearly to done.

    Check by: ssh -T git@gitlab.com

    You will get: Welcome to GitLab, @joy4!

    I know, I’m answering this very late and even StackOverflow confirmed if I really want to answer. I’m answering because no one actually described the actual problem so wanted to share the same.

    The Basics

    First, understand that what is the remote here. Remote is GitLab and your system is the local so when we talk about the remote origin , whatever URL is set in your git remote -v output is your remote URL.

    The Protocols

    Basically, Git clone/push/pull works on two different protocols majorly (there are others as well)-

    When you clone a repo (or change the remote URL) and use the HTTPs URL like https://gitlab.com/wizpanda/backend-app.git then it uses the first protocol i.e. HTTP protocol.

    While if you clone the repo (or change the remote URL) and uses the URL like git@gitlab.com:wizpanda/backend-app.git then it uses the SSH protocol.

    HTTP Protocol

    In this protocol, every remote operation i.e. clone, push & pull uses the simple authentication i.e. username & password of your remote (GitLab in this case) that means for every operation, you have to type-in your username & password which might be cumbersome.

    So when you push/pull/clone, GitLab/GitHub authenticate you with your username & password and it allows you to do the operation.

    If you want to try this, you can switch to HTTP URL by running the command git remote set-url origin .

    To avoid that case, you can use the SSH protocol.

    SSH Protocol

    A simple SSH connection works on public-private key pairs. So in your case, GitLab can’t authenticate you because you are using SSH URL to communicate. Now, GitLab must know you in some way. For that, you have to create a public-private key-pair and give the public key to GitLab.

    Now when you push/pull/clone with GitLab, GIT (SSH internally) will by default offer your private key to GitLab and confirms your identity and then GitLab will allow you to perform the operation.

    So I won’t repeat the steps which are already given by Muhammad, I’ll repeat them theoretically.

    1. Generate a key pair `ssh-keygen -t rsa -b 2048 -C «My Common SSH Key»
    2. The generated key pair will be by default in

    /.ssh named id_rsa.pub (public key) & id_rsa (private key).

  • You will store the public key to your GitLab account (the same key can be used in multiple or any server/accounts).
  • When you clone/push/pull, GIT offers your private key.
  • GitLab matches the private key with your public key and allows you to perform.
  • You should always create a strong rsa key with at least 2048 bytes. So the command can be ssh-keygen -t rsa -b 2048 .

    General thought

    Both the approach have their pros & cons. After I typed the above text, I went to search more about this because I never read something about this.

    Читайте также:  Mac os для управления мониторами
    Оцените статью