Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

git push origin master: permission denied (public key) error

Tags:

git

amazon-ec2

I have set up a git repo on my amazon ec2 ubuntu server instance. I have been trying to push the code onto the server's repo from my local machine. The steps that I followed are:

ssh-add /path/to/myEC2publickey

On my EC2 Instance

mkdir /path/my_project.git
cd /path/my_project.git
git init --bare

Later on my localhost,

cd the_project 
git init git add . 
git commit -m "Initial git commit message" 
git remote add origin [email protected]:the_project.git 
git config --global remote.origin.receivepack "git receive-pack" 
git push origin master

Since I was getting a Permission Deined (public key) error while executing the last command (i.e. git push origin master), I set the public key using the steps given on a forum that included -

ssh-keygen -t rsa -C "[email protected]"
eval 'ssh-agent -s'
ssh-add

I was able to add the public key but I am still facing the Permission Denied (public key) : Error.

I'm new to git and have been looking forward to shift all my code into a git repo.

Any help would be greatly appreciated.

like image 955
Amit Nandan Periyapatna Avatar asked Jan 17 '14 07:01

Amit Nandan Periyapatna


1 Answers

One step you seem to have missed (or didn't include in your description) is the publication of the public key on the server side.
Upload your public ssh key and add it to the ~username/.ssh/authorized_keys file.

Also, try it (for testing) first with a private key without passphrase (no need to ssh-add your key to an ssh agent)

Finally, make sure your ssh keys are with standards names (id_rsa and id_rsa.pub), with the right protection:

  • on the local side
  • in the remote side

Finally, an ssh -Tvvv [email protected] should tell you more, if the previous steps didn't solve the issue.

like image 127
VonC Avatar answered Mar 28 '23 20:03

VonC