Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix a permission denied (publickey) error for a git submodule update in the Github Travis CI build?

I cannot update the git submodule, with the error:

$ git submodule init Submodule 'build/html' ([email protected]:quadroid/clonejs.git) registered for path 'build/html' ... $ git submodule update Cloning into 'build/html'... Warning: Permanently added 'github.com,207.97.227.239' (RSA) to the list of known hosts. Permission denied (publickey). fatal: Could not read from remote repository. 

But when I do the same tasks locally, everything is OK.

How do I fix this so that the Travis CI build passes and I can still click on the submodule in the repo to direct to it?

like image 498
Quadroid Avatar asked Mar 28 '13 04:03

Quadroid


People also ask

How do I fix Permission denied in GitHub?

Always use the "git" user$ ssh -T [email protected] > 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 [email protected] > Hi username!

What does git GitHub Permission denied Publickey mean?

GitHub's Permission denied (publickey) error is usually caused by one of the following three issues: You have used an incorrect email address in the GitHub SSH URL. You have not configured your public SSH key in your GitHub account. You must create GitHub SSH keys to be used by the secure shell.

How do I fix git GitHub Permission denied Publickey fatal could not read from remote repository?

The “Permission denied (publickey). fatal: Could not read from remote repository” error is caused by an issue with the way in which you authenticate with a Git repository. To solve this error, make sure your key is being used on your Git account. If it is not, add your key to Git.


2 Answers

This can (thankfully) be easily solved by modifying the .gitmodules file on-the-fly on Travis, so that the SSH URL is replaced with the public URL, before initializing submodules. To accomplish this, add the following to .travis.yml:

# Handle git submodules yourself git:     submodules: false # Use sed to replace the SSH URL with the public URL, then initialize submodules before_install:     - sed -i 's/[email protected]:/https:\/\/github.com\//' .gitmodules     - git submodule update --init --recursive 

Thanks to Michael Iedema for his gist from which I derived this solution.

If your submodules are private repositories, it should work to include credentials in the https URLs, I recommend making a GitHub access token with restricted permissions for this purpose:

# Replace <user> and <token> with your GitHub username and access token respectively - sed -i 's/[email protected]:/https:\/\/<user>:<token>@github.com\//' .gitmodules 
like image 95
aknuds1 Avatar answered Sep 21 '22 13:09

aknuds1


I'd recommend using the https scheme for submodules, as that'll allow you to pull on Travis and push locally: https://github.com/quadroid/clonejs.git.

like image 42
sarahhodne Avatar answered Sep 18 '22 13:09

sarahhodne