1

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!

Ryan Dhungel
  • 3,637
  • 4
  • 19
  • 26
  • 1
    Check if you overwrote your ssh keys, if yes, add the fresh ones in github. – Anshul Goyal Apr 08 '18 at 03:44
  • Is it necessary to add shh keys in github for all the projects? I dont remember adding ssh keys to any github repos unless I wanted it to push to live server such as digital ocean.. – Ryan Dhungel Apr 08 '18 at 03:45
  • Can you add the output of `git remote show origin` for one repo that works and one that doesn't? ssh keys are set at account level not repo level. – Anshul Goyal Apr 08 '18 at 03:50
  • remote origin Fetch URL: https://github.com/kaloraat/larablog.git Push URL: https://github.com/kaloraat/larablog.git HEAD branch: master Remote branch: master tracked Local branch configured for 'git pull': master merges with remote master Local ref configured for 'git push': master pushes to master (up to date) – Ryan Dhungel Apr 08 '18 at 03:53
  • I can still run git push origin master on my old projects in github. They work fine, Just the new ones are having issues.. – Ryan Dhungel Apr 08 '18 at 03:55
  • 1
    Were the new projects cloned using the ssh url instead of https ones? https://help.github.com/articles/which-remote-url-should-i-use/ – Anshul Goyal Apr 08 '18 at 03:58
  • I am trying to push a project from my local computer to github. I created a fresh new repo where i am trying to push. – Ryan Dhungel Apr 08 '18 at 04:00
  • 1
    Possible duplicate of [GitHub Error Message - Permission denied (publickey)](https://stackoverflow.com/questions/12940626/github-error-message-permission-denied-publickey) – phd Apr 08 '18 at 14:18

2 Answers2

1

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

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
0

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

git remote add origin git@github.com: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..

Ryan Dhungel
  • 3,637
  • 4
  • 19
  • 26