You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 16.04 EC2实例启用Web服务器后SSH连接超时求助

Troubleshooting SSH Timeout on Ubuntu 16.04 EC2 Instance After Enabling Web Server

Hey Brad, let’s walk through this SSH timeout issue step by step—since your security group rules already look properly configured (22 and 80 ports open to all traffic), we can rule that out as the immediate cause and focus on other common culprits that pop up after setting up a web server.

Here are the actionable steps to diagnose and fix the problem:

1. Check if the SSH service is running on the instance

After installing a web server, it’s possible the SSH service got stopped accidentally, or a configuration tweak broke it. If you have access via EC2 Serial Console (if enabled) or AWS Systems Manager Session Manager (if you set up SSM Agent beforehand), run these commands:

  • Verify SSH status: sudo service ssh status
  • If it’s inactive, start the service: sudo service ssh start
  • Ensure it launches on boot: sudo update-rc.d ssh defaults

2. Inspect the instance’s local firewall rules

Web server installations often enable ufw (Ubuntu’s default firewall) automatically, which might block SSH traffic even if your security group allows it:

  • Check current firewall rules: sudo ufw status
  • If port 22 isn’t listed as allowed, add it: sudo ufw allow 22/tcp
  • Reload the firewall to apply changes: sudo ufw reload

3. Verify SSH configuration file settings

Double-check that your SSH daemon config hasn’t been modified incorrectly:

  • Open the config file: sudo nano /etc/ssh/sshd_config
  • Confirm these key lines are set correctly (uncommented and valid):
    • Port 22 (make sure you didn’t accidentally change this to another port)
    • PermitRootLogin yes (only if you log in as root; using a non-root user is recommended)
    • PasswordAuthentication yes (if you use password-based login; skip this if you rely on SSH keys)
  • Save changes and restart SSH: sudo service ssh restart

4. Check for resource exhaustion

Web servers can consume excessive CPU/memory, especially if misconfigured, which might make the SSH service unresponsive:

  • Head to the EC2 Console and check the instance’s Monitoring tab for CPU usage, memory, and disk I/O metrics.
  • If resources are maxed out, stop the web server temporarily to free up capacity:
    • For Apache: sudo service apache2 stop
    • For Nginx: sudo service nginx stop
  • Try connecting via SSH again once resources are available.

5. Validate network routing and reachability

  • First, test if the instance’s public IP is reachable: ping ec2-{My IP}.us-east-2.compute.amazonaws.com
    • If ping fails, confirm your instance is in a subnet with a route to an Internet Gateway (IGW) (check your VPC’s route table). If it’s in a private subnet, ensure a NAT Gateway is configured for outbound traffic.
  • If ping works but SSH times out, try connecting from another instance in the same VPC. If that succeeds, the issue is likely with your local network (though your security group changes make this less probable).

内容的提问来源于stack exchange,提问作者Brad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 07:20:47