1

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?

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
Incerteza
  • 32,326
  • 47
  • 154
  • 261

1 Answers1

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

Anshul Goyal
  • 73,278
  • 37
  • 149
  • 186
  • what does `mv hooks/post-update.sample hooks/post-update` and other commands do in a nutshell? – Incerteza Mar 15 '14 at 05:55
  • There is a git hook in a bare directory, which is needed while pushing over server is called but may not be otherwise needed. So it is in a `.sample` format initially, and the `mv` renames it to the usable format (without any extension). The hook is then called in `git update-server-info`. Read more in the link I shared. – Anshul Goyal Mar 15 '14 at 05:58
  • by the way, "a" can be removed from chmod to be "chmod +x hooks/post-update" – Incerteza Mar 15 '14 at 12:26
  • would you mind taking a look at this http://stackoverflow.com/questions/22424563/git-push-pushes-nothing ? – Incerteza Mar 15 '14 at 13:41
  • Yeah, check my answer there. – Anshul Goyal Mar 15 '14 at 14:06