Anybody seen this error and know what to do?
I\'m using the terminal, I\'m in the root, the GitHub repository exists and I don\'t know what to do now.
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.
Once scenario where this will happen is when you follow GitHub instructions after you create your repository. Git will instruct you to add your remote with something like this.
git remote add origin git@github.com:<user>/<project>.git
Replace what's in <> with values related to your account.
The solution is to remove the .git
suffix. Add the remote as follows:
git remote add origin git@github.com:<user>/<project>
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.
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
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!! :)
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