I have a strange problem with cloning a git repository from an amazon ec2 server. It works without any problems on one of my computers running ubuntu 12.04, while on another one using 12.10 it gives me an error:
ssh: Could not resolve hostname ec2server: Name or service not known
fatal: The remote end hung up unexpectedly
It's like it is not recognizing my config file. I use the following git command to clone :
sudo git clone ec2server:/var/www/project.git
or
sudo git clone ec2xxx.compute-1.amazonaws.com:/var/www/project.git
The two config files are identical on both computers, inside the ~./ssh with the following content:
Host ec2server
Hostname ec2XXX.compute-1.amazonaws.com
User ubuntu
IdentityFile ~/.ssh/mykey.pem
If I substitute the ec2server with the actual address I get the following error:
Cloning into 'project'...
Permission denied (publickey).
fatal: The remote end hung up unexpectedly
Thanks in advance.
It usually is a permission issue.
The chmod
on the parent directories of your config file might be different between your two computers.
(and I am not talking about just the immediate parent directory .ssh
, but also all the parent directories)
See "Git SSH authentication", but also know that if any of the parent directories is writable for group or world, ssh won't work.
Note also that your second command is not right, and should be:
git clone [email protected]/var/www/project.git
no ':
' (a ':
' means using a config
file, with an scp
-like syntax)
it can only work if you have ~/.ssh/id_rsa
and ~/.ssh/id_rsa.pub
though.
If you have mykey.pem, then you need a config
file for ssh to know where are your public and private keys, which means only this can work:
git clone ec2server:/var/www/project.git
One other chack (after this thread and this forum) is to check if there is any DNS/DHCP issue (a bit like in "Working with git behind a dynamic DNS").
Host ec2server
Hostname 1xx.xxx.xxx.xxx # ip address of ec2XXX.compute-1.amazonaws.com
User ubuntu
IdentityFile ~/.ssh/mykey.pem