Git Submodule - Permission Denied

62,990

Solution 1

I was facing the same issue. The problem was on your github repo , you might be using some old ssh key.

You need to update the current ssh key.

Steps involved are:

1. vim ~/.ssh/id_rsa.pub
2. copy the ssh key
3. Go to the github settings
4. Select the option ssh keys
5. Remove the old ssh keys not used anymore.
6. Add a new ssh key.
7. Try running the "git submodule update --recursive"

This worked for me !!

Solution 2

  • On Windows:

In my case, it was complaining about the same issue when I was using a regular command line (Git CMD). Then I tried with Git Bash and no issue no more.

Solution 3

I had this issue. In my case, the public key (~/.ssh/id_rsa.pub) wasn't set up on the server properly.

Ensure you're getting all the submodules:

Reference: Git update submodules recursively

# This must be called twice. Once for new and once for existing submodules.
git submodule update --init --recursive
git submodule update --recursive

To diagnose permission issues with your key:

To check details of your submodules

  • Open .gitmodules in the project root folder and ensure things look okay. As recommended by @VonC try cloning them in a separate folder.
  • You might want to switch submodules from using SSH to HTTPS. That will let you type a username and password. But that can cause issues with your teammates and build automation. Speak to them first.

Solution 4

In my case the issue was caused by console which did not ask me for a password. Solution was to change the console from CMDER to Gitbash. When I used CMDER it does not show the password window which caused this access denied issue.

Solution 5

Interestingly, in a similar occasion using the HTTPS link worked for me.

Share:
62,990

Related videos on Youtube

Max
Author by

Max

Updated on July 09, 2022

Comments

  • Max
    Max almost 2 years

    I am not able to clone the submodule existing within my private git repository. I do have access to entire repository,

    Have used the below commands but dint work, please help. What is the right way to clone the submodules in an existing repository?

    djrecker$ git submodule update --init --recursive
    Submodule 'Path' ([email protected]:Path) registered for path 'App'
    Cloning into 'Path'...
    Permission denied (publickey).
    fatal: Could not read from remote repository.
    
    • VonC
      VonC over 9 years
      Can you clone [email protected]:Path independently? Just to check that a direct clone would work and that you do have access.
    • Max
      Max over 9 years
      Yes i did that and i get the entire repo except the submodule,
    • VonC
      VonC over 9 years
      Can you check the .gitmodules content (in the repo you just cloned), and try cloning the url referenced in it.
    • Max
      Max over 9 years
      Can you please tell me how do i do that ? I am a little new to git so please bare with me.
    • VonC
      VonC over 9 years
      See if the repo you just cloned has a .gitmodules file in it. Then open that file, and try cloning the url(s) listed in it.
    • Ke Li
      Ke Li over 4 years
      As @VonC mentioned, after checking the contents within .gitmodules, I see there's a different repo than the main one in which I have to refresh my ssh key. After doing so, it's working.
  • famfamfam
    famfamfam about 5 years
    It must be accepted answer by smart way, just go to submodule folder then clone https link -> WORK 100%
  • Arcyno
    Arcyno over 3 years
    the issue is when it occurs in a windows gitlab runner... it uses CMD by default !
  • Alexis Wilke
    Alexis Wilke over 3 years
    @famfamfam Absolutely not. If you need to do edits and be able to push your changes, you don't want to use the HTTPS protocol.
  • Adam Johns
    Adam Johns over 2 years
    I had never configured an ssh key, but everything worked fine after I configured my ssh key
  • tapizquent
    tapizquent over 2 years
    Was getting the same issue with Windows Terminal. Using Git Lab and running git submodule update fixed it
  • Özgür Ağcakaya
    Özgür Ağcakaya almost 2 years
    + This might be a problem with the password protected keys. I've prompted to re-enter the password only from gitbash.