I am trying to use this tutorial to set up a git remote repo on my server: http://toroid.org/ams/git-website-howto

But when I try to push to the server, I get this error:

Permission denied (publickey).
fatal: The remote end hung up unexpectedly

So it seems like git can't ssh the server because of some auth key issue. I can SSH into the server fine from Terminal by using ssh aws1 due to the set up of my ssh config file.

~/.ssh/config file:

Host aws1
        User ubuntu
        IdentityFile ~/.ssh/ec2_key.pem

The git commands I am using to add the remote and push:

git remote add web  ssh:// 

git push web +master:refs/heads/master

I think my problem is i don't quite understand fully how to use ssh key-pairs. The tutorial says:

"I assume that the web site will live on a server to which you have ssh access, and that things are set up so that you can ssh to it without having to type a password (i.e., that your public key is in ~/.ssh/authorized_keys and you are running ssh-agent locally)."

I don't know what ssh-agent is and I don't even have an authorized_keys file on my machine (I do have one called known_hosts). I thought using the ssh config file would be adequate because that allows me to ssh from the terminal without a password but apparently that is not correct. What am I doing wrong?

Server: EC2 instance, Ubuntu 12.04, AWS elastic ip

Dev Machine: OS X 10.7.5, zsh shell


Why don't you simply use aws1 in your remote ? This way, you can reuse your .ssh/config configuration for aws1:

git remote add web ssh://aws1/home/ubuntu/somedirectory.git

Git uses the ssh command to connect, so everything that applies to the ssh command applies to Git.

Otherwise, you will need to specify the URL, user in the remote, as in ssh://ubuntu@ And because there is no way to specify which private key should be used, you need to configure it in .ssh/config anyway.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.