How do I troubleshoot problems connecting to my Amazon EC2 Linux instance using SSH?
Last updated: 2020-04-16
I'm unable to connect to my Amazon Elastic Compute Cloud (Amazon EC2) Linux instance. How do I troubleshoot and resolve this issue?
To troubleshoot the issue, log in to the EC2 instance over SSH with verbose messaging on. Use the output messages from the SSH client to determine the type of issue, and then follow the troubleshooting steps to resolve the issue.
Troubleshoot the issue
1. Log in to the EC2 instance over SSH with verbose messaging on.
user@localhost:~$ ssh -v -i my_key.pem email@example.com
The preceding example uses my_key.pem for the private key file, and a user name of firstname.lastname@example.org. Substitute your key file and your user name for the example's key file and user name. For more information, see Connecting to Your Linux Instance Using SSH.
2. Use the output messages from the SSH client to determine the type of issue, and then use one of the following troubleshooting steps to resolve the issue.
Error: "Connection timed out" or "Connection refused": For information on resolving this error, see I'm receiving "Connection refused or "Connection timed out" errors when trying to SSH to my EC2 instance. How do I resolve this?
For information on resolving "connection timed out" errors on a virtual private cloud (VPC), see How do I troubleshoot instance connection timeout errors in Amazon VPC?
Error: "Permission denied" or "Authentication failed": For information on resolving this error, see I'm receiving "Permission denied (publickey)" or "Authentication failed, permission denied" errors when trying to access my EC2 instance. How do I resolve this?
Error: "Server refused our key": For more information on resolving this error, see How can I log into my Amazon EC2 instance if I receive an error that the server refused our key?
Automatically troubleshoot SSH errors
You can run the AWSSupport-TroubleshootSSH Automation document to automatically find and correct some SSH errors. For more information, see I'm receiving errors when trying to connect to my EC2 instance using SSH. How can I use the AWSSupport-TroubleshootSSH automation workflow to troubleshoot SSH connection issues?