简体   繁体   中英

SSH into EC2 and can't execute git clone command

I've ssh'd in to a new ec2 instance, which I'm setting up for our production environment, and tried to git clone a project from another ec2 instance which we are using as our development box but I get the below error.

$ git clone ubuntu@?.??.??.??6:/var/git/our-project.git our-project
Cloning into 'our-project'...
ssh: connect to host ?.??.??.??6 port 22: Connection timed out
fatal: Could not read from remote repository.

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

I've created a public/private key pair on the production box to connect to the development box and added the public key to the dev box's authorized_keys . This is the same setup I've used on my local machine, which works.

I also have an AWS security group configured for the dev box which has the production ec2s public IP added to it to allow ssh inbound connections on port 22.

Could the problem be that I can't ssh into a machine and perform another ssh from within it, which is what in effect the git clone command is doing? I also tried what was suggested in this answer to run the git clone command from my local machine with the following, but as you can see this gives me the same error message.

ssh ubuntu@5?.??.??.??8 'git clone ubuntu@?.??.??.??6:/var/git/our-project.git /var/www/our-project'
Cloning into '/var/www/houseofireland'...
ssh: connect to host ?.??.??.??6 port 22: Connection timed out
fatal: Could not read from remote repository.

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

Would be very grateful for any possible causes or solutions to this issue.

As pointed out in the comments, this is not a git problem but rather ssh one.

Generally, it is possible to SSH from one EC2 instance to another but keep in mind the following:

  • EC2 instances have a public IP which you can use for accessing them from outside the AWS network and a private IP which is used internally. This IP has the form 10.XXX
  • When two EC2 instances communicate with each other, they use different DNS server than the one which is used when accessing them from outside the AWS network - thats why the public IP (or hostname, if you will) won't work

What you should do, is to put the instance from which you are making the SSH tunnel on a white list in the SecurityGroup of the second instance (assuming they they are on the same account).

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM