git push: permission denied (public key)

I was facing same problem and here is what I did that worked for me.

Use ssh instead of http. Remove origin if its http.

git remote rm origin

Add ssh url

git remote add origin git@github.com:<username>/<repo>.git

Generate ssh key inside .ssh/ folder. It will ask for path and passphrase where you can just press enter and proceed.

cd ~/.ssh
ssh-keygen

Copy the key. You can view your key using –

cat ~/.ssh/id_rsa.pub

If you hadn’t specified a different path then this will be the default path.

Add this key to your github account.

Next do –

ssh -T git@github.com

You will get a welcome message in your console.

cd into to your project folder. git push -u origin master now works!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)