我正在尝试通过SSH连接到EC2实例。当我尝试使用ssh -i "test.pem" ec2-user@xx.xx.xx.xx
连接到实例时,出现错误:ssh: connect to host xx.xx.xx.xx port 22: Operation timed out
。
EC2实例配置
平台:Amazon Linux
AMI:ami-0841edc20334f9287
实例类型:t2.micro
公共IPv4:关联的弹性IPv4
EC2实例关联的VPC子网配置:
路由表:(目标-目标)
10.0.0.0/24 - local
0.0.0.0/0 - igw-...
ACL :(类型-协议-端口范围-源)
入站
SSH - TCP - 22 - 0.0.0.0/0
出站
HTTPS - TCP - 443 - 0.0.0.0/0
安全组:(类型-协议-端口范围-源)
入站
SSH - TCP - 22 - xx.x.xxx.xxx/xx (My IP)
出站
HTTPS - TCP - 443 - 0.0.0.0/0
尝试:
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type:
text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
iptables -F
service sshd restart
--//
导致相同错误的原因:
ssh: connect to host public.ip port 22: Operation timed out
ssh -i "test.pem" ec2-user@public.ip
ssh -i "test.pem" root@public.ip
导致相同错误的原因:
ssh: connect to host public.ip port 22: Operation timed out
我尝试在同一VPC中使用我的公共子网,并且能够通过ssh连接到ec2。比较公共子网和私有子网时,唯一的区别是公共子网的NACL允许所有流量入站流量。
在控制台上连接EC2实例连接后,即使大约10分钟后,终端窗口仍为空白。
答案 0 :(得分:1)
您的NACL具有ssh的入站规则。您还应该在出站NACL规则中允许返回ssh通信。因为与安全组不同,NACL是无状态的。
除此之外,您还应该为入站和出站NACL规则允许临时端口范围。临时端口是发起请求的客户端选择作为源端口的1024至65535之间的随机端口。