简体   繁体   中英

SSH connection timed out while connecting to ec2 after apache2 installation

I created an ec2 instance in AWS with ubuntu AMI and done all necesaary things to connect to the domain by setting up elsatic IP, Security Group, Route 53. Then I got the PEM file and connected to the SSH using private keys.

It is all working fine till I installed apache2 and restarted the apache server.

Then after, it is showing connection timed out to port 22 (SSH)

SSH 连接错误

here is the security group inbound rules

安全组入站规则

then checked in instance log got this thing at the bottom

[[0;32m  OK  [0m] Started The Apache HTTP Server.
[[0;32m  OK  [0m] Started Dispatcher daemon for systemd-networkd.
[[0;32m  OK  [0m] Started Snappy daemon.
         Starting Wait until snapd is fully seeded...
[[0;32m  OK  [0m] Started Wait until snapd is fully seeded.
[[0;32m  OK  [0m] Reached target Multi-User System.
[[0;32m  OK  [0m] Reached target Graphical Interface.
         Starting Update UTMP about System Runlevel Changes...
         Starting Apply the settings specified in cloud-config...
[[0;32m  OK  [0m] Started Update UTMP about System Runlevel Changes.
[   13.456104] cloud-init[1033]: Cloud-init v. 18.3-9-g2e62cb8a-0ubuntu1~18.04.2 running 'modules:config' at Wed, 06 Feb 2019 12:07:07 +0000. Up 13.29 seconds.
[[0;32m  OK  [0m] Started Apply the settings specified in cloud-config.
         Starting Execute cloud user/final scripts...
[   14.093385] cloud-init[1060]: Cloud-init v. 18.3-9-g2e62cb8a-0ubuntu1~18.04.2 running 'modules:final' at Wed, 06 Feb 2019 12:07:08 +0000. Up 13.95 seconds.
[   14.108125] cloud-init[1060]: Cloud-init v. 18.3-9-g2e62cb8a-0ubuntu1~18.04.2 finished at Wed, 06 Feb 2019 12:07:08 +0000. Datasource DataSourceEc2Local.  Up 14.08 seconds
[[0;32m  OK  [0m] Started Execute cloud user/final scripts.
[[0;32m  OK  [0m] Reached target Cloud-init target.

EDIT:

AMI has some issues, created new instance and configured all again now it is working fine.

May be you have enable firewall during Apache installation and allow only few ports in firewall.

I follow this video and was able to connect with instance through session manager. Steps to connect with instance though session manager when ssh not works

A. Create Role and assign policy

1. Choose entity type AWS and use case ec2

在此处输入图片说明

2. Attach policy

在此处输入图片说明

3. tags skip

4. Review: Add role name 在此处输入图片说明


B. Attach above role with instance and save. 在此处输入图片说明 c. Reboot your instance and try to connect with session manager在此处输入图片说明

After login just disable firewall sudo ufw disable and check all inbound rule defined in security group should work

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