Can't push to repository on EC2 - Could not re

2019-07-29 18:47发布

问题:

I can successfully connect to my ec2 instance by ssh:

ssh -i amazon_ec2_123.pem ubuntu@xx.xx.xx.xxx

where xx.xx.xx.xxx is my elastic ip address. Then I created a folder there called my_project.git and ran git init --bare in it.

Then I did this:

cat ~/.ssh/id_dsa.pub | ssh -i amazon_ec2_123.pem ubuntu@xx.xx.xx.xxx "cat >> .ssh/authorized_keys"

At my local machine from the projects' source directory I did this:

git remote add ec2 ssh://ubuntu@xx.xx.xx.xxx:/home/ubuntu/my_project.git

However, when I tried to push to the repo, I got the error:

ssh: Could not resolve hostname xx.xx.xx.xxx:: Name or service not known
fatal: Could not read from remote repository.

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

What have I done wrong?

回答1:

First of all, make sure that you are able to login with your new ssh keys into your EC2 instance.

Once you are sure that the ssh connection itself works, then, in your bare repository, run

cd git_repo.git
mv hooks/post-update.sample hooks/post-update
chmod a+x hooks/post-update

git update-server-info

Once you have done that, you can add the remote

git remote add ec2 ubuntu@xx.xx.xx.xxx:/home/ubuntu/my_project.git

And it should work. You can read more about setting up git on the server on git-scm