简体   繁体   English

两个 EC2 实例之间的 SSH 和 SCP 超时

[英]SSH & SCP between two EC2 instances times out

I would like to transfer/tunnel between two Amazon EC2 instances via ssh and scp (from A to B, as shown below).我想通过sshscp (从 A 到 B,如下所示)在两个 Amazon EC2 实例之间传输/隧道。

Both instances are running Ubuntu 18.04.两个实例都运行 Ubuntu 18.04。

  • Instance A: ec2-34-200-134-210.compute-1.amazonaws.com实例 A:ec2-34-200-134-210.compute-1.amazonaws.com
  • Instance B: ec2-34-199-133-209.compute-1.amazonaws.com实例 B:ec2-34-199-133-209.compute-1.amazonaws.com

Run on Instance A:在实例 A 上运行:

  • $ ssh-keygen -t rsa -b 4096
  • Result put at /home/ubuntu/.ssh/id_rsa and /home/ubuntu/.ssh/id_rsa.pub结果放在/home/ubuntu/.ssh/id_rsa/home/ubuntu/.ssh/id_rsa.pub
  • $ chmod 400 /home/ubuntu/.ssh/id_rsa.pub
  • Copy /home/ubuntu/.ssh/id_rsa.pub contents复制/home/ubuntu/.ssh/id_rsa.pub内容

Run on Instance B:在实例 B 上运行:

  • $ sudo vim /etc/ssh/sshd_config
  • Add/uncomment lines:添加/取消注释行:
    • RSAAuthentication yes
    • PubkeyAuthentication yes
  • Append copied contents of /home/ubuntu/.ssh/id_rsa.pub from Instance A to /home/ubuntu/.ssh/authorized_keys/home/ubuntu/.ssh/id_rsa.pub从实例 A 复制的内容附加到/home/ubuntu/.ssh/authorized_keys

Now, testing from A to B:现在,从 A 到 B 进行测试:

ubuntu@ip-XX-XX-XX-XX:~$ ssh -T ubuntu@ec2-34-199-133-209.compute-1.amazonaws.com
ssh: connect to host ec2-34-199-133-209.compute-1.amazonaws.com port 22: Connection timed out

ubuntu@ip-XX-XX-XX-XX:~$ touch testfile.txt && \
>    scp testfile.txt ubuntu@ec2-34-199-133-209.compute-1.amazonaws.com:/home/ubuntu/
ssh: connect to host ec2-34-199-133-209.compute-1.amazonaws.com port 22: Connection timed out

What am I missing here?我在这里缺少什么? Do I need to change additional file permissions?我需要更改其他文件权限吗?

The issue was with Inbound Rules on the security group that applied to the cluster of instances.问题在于应用于实例集群的安全组上的入站规则。

Solution:解决方案:

  1. On the EC2 dashboard at https://console.aws.amazon.com/ec2/ , navigate to Security Groups on the left-hand pane.https://console.aws.amazon.com/ec2/的 EC2 仪表板上,导航到左侧窗格中的安全组。
  2. Select the security group that applies to Instance B, the instance to which you want to tunnel to.选择适用于实例 B 的安全组,即您要通过隧道连接到的实例。
  3. Add an Inbound Rule on the Inbound tab > Edit.在入站选项卡 > 编辑上添加入站规则。 Type: SSH;类型:SSH; Port: 22, IP Address: 10.XX.XX.XX/32 where 10.XX.XX.XX is the private IPv4 of Instance A.端口:22,IP 地址:10.XX.XX.XX/32 其中 10.XX.XX.XX 是实例 A 的私有 IPv4。
  4. Save the rule and log out/log in of Instance A, then re-test as above.保存规则并注销/登录实例 A,然后按上述方法重新测试。

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

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