Kosmo
Kosmo

Reputation: 69

How to resolve remote SSH push github error

I have created SSH key linked to github. I am trying to remotely push a file to the created repository

these are my code

git init
git add README.md
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/username/demo_repo2.git
git push -u origin main

But it is giving me error as :

[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.

Please make sure you have the correct access rights and the repository exists.

I have checked whether ssh key is linked , and it is. It is even giving

git remote -v

origin  [email protected]:user/repo2.git (fetch)
origin  [email protected]:user/repo2.git (push)

I tried almost all answers , but not working . Please someone help me

Upvotes: 3

Views: 2003

Answers (2)

iceweasel
iceweasel

Reputation: 786

You have created ssh key and linked the public key to your github account which need to be done fisrt .

Then you need to add your RSA key to your ssh-agent and perform an authentication command to test whether your key has been synced with github . These can be done by following commands.(after adding public key to github)..

eval "$(ssh-agent -s)"  // evaluate process ID
ssh-add ~/.ssh/<required key> //add key to agent 
ssh -T [email protected] 
after these you'll get an output like this .. "Hi <your_user_name>! You've successfully authenticated, but GitHub does not provide shell access."

Upvotes: 1

VonC
VonC

Reputation: 1329542

It should not give you this error, since you have set an HTTPS URL with:

git remote add origin https://github.com/username/demo_repo2.git

Check git config -l for any url."[email protected]:".insteadOf https://github.com/ directive.

If git remote -v does give you an SSH URL, that means the first git remote add origin must have failed.
You can force an HTTPS URL with:

cd /path/to/my/repo
git remote set-url  origin https://github.com/username/demo_repo2.git

Upvotes: 2

Related Questions