Ryan Dhungel
Ryan Dhungel

Reputation: 3775

git push Permission denied (publickey). Please make sure you have the correct access rights

When I run git push -u origin master which is a brand new repository, 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.

I can not push any project to github, even the fresh one just created. It was all working fine. Then yesterday I setup digital ocean deployment to one of my project, which involved ssh key generate etc. Now the digital ocean part and the project that is pushed to github is working fine but I can not push any changes to github on any of my other projects..

So this question has nothing to do with digital ocean, adding ssh key to github repo etc. All I want is push projects to github.. simple test projects but I can not. I get the above error.

The same question has been asked before but they are about pulling a project from github or projects that requires to have ssh key in the github repository.

But in my case, I do not need to add ssh key in the repository, they are just regular projects. I just want to push to github as I could do before..

Any solutions? Thanks!

Upvotes: 1

Views: 586

Answers (2)

Ryan Dhungel
Ryan Dhungel

Reputation: 3775

When you try to add your local project to github like so:

git remote add origin [email protected]:kaloraat/your-repo.git

You might get this error: fatal: remote origin already exists In that case run this:

git remote rm origin

Then do this (copy/paste the url of your-repo):

git remote add origin https://github.com/kaloraat/laratweet

Then run git push origin master

This worked for me, so I decided to answer myself. I did not have to do anything with ssh keys and other complicated stuff..

Upvotes: 0

VonC
VonC

Reputation: 1324278

Your git remote -v command shows https URL, not SSH ones.

And yes, you need to add ssh keys only if you want to push back to a repo (clone/pull do not necessitate authentication)

Make sure you don't have a git credential helper that might have cached the wrong https credentials (username/password): git config --global credential helper

Upvotes: 1

Related Questions