简体   繁体   English

SSH进入EC2并且无法执行git clone命令

[英]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. 我已经进入了一个新的ec2实例,我正在为我们的生产环境设置,并试图从另一个我们用作开发框的ec2实例git clone一个项目,但是我得到了以下错误。

$ 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 . 我在生产框上创建了一个公钥/私钥对,以连接到开发框,并将公钥添加到开发框的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. 我还为开发箱配置了一个AWS安全组,其中添加了生产ec2s公共IP以允许端口22上的ssh入站连接。

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? 可能问题是我不能ssh到一台机器并从其中执行另一个ssh ,这实际上是git clone命令正在做什么? 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. 我也尝试了在这个答案中建议使用以下内容从本地计算机运行git clone命令,但正如您所看到的,这给了我相同的错误消息。

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. 正如评论中所指出的,这不是一个git问题,而是ssh问题。

Generally, it is possible to SSH from one EC2 instance to another but keep in mind the following: 通常,可以从一个EC2实例SSH到另一个实例,但请记住以下内容:

  • 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. EC2实例具有可用于从AWS网络外部访问它们的公共IP以及内部使用的专用IP This IP has the form 10.XXX 此IP的格式为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 当两个EC2实例相互通信时,它们使用的DNS服务器与从AWS网络外部访问时使用的DNS服务器不同 - 这就是为什么公共IP(或主机名,如果您愿意)将无法工作的原因

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). 你应该做的是将你在哪个SSH隧道的实例放在第二个实例的SecurityGroup中的白名单上(假设它们在同一个帐户上)。

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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