- Newest
- Most votes
- Most comments
Is the error message just "Connection refused" or is there any more to it? Does this come up right away, or does it wait for a while?
You'll likely need the username as part of your command, this varies according to the OS (on Amazon Linux and RHEL it's ec2-user
, CentOS it's centos
, Ubuntu it's ubuntu
) and also specify your private key in the command (I know you say you've saved it to your profile, but no harm in explicitly stating it just for troubleshooting). So something like ssh -i /path/to/mykeyfile.pem ec2-user@ec2-<blah blah>.compute-1.amazonaws.com
if ithis still fails, try verbose mode to get more detailed error messages ssh -vvv -i ....
This AWS doc may help too https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/AccessingInstancesLinux.html#AccessingInstancesLinuxSSHClient
Its probably the Security Group attached to EC2 Instance.
-
Check the security group settings for your EC2 instance, and see if the inbound rules allow SSH traffic from your IP address ( or for testing alone set it to 0.0.0.0/0) . You can check this in the EC2 console under the "Security Groups" section.
-
Set the correct permissions to your private key :
chmod 400 /path/to/private/key.
If you're using a different username on the EC2 instance than your local username, you'll need to specify the correct username when you SSH. For example, if your EC2 instance uses the username "ec2-user", you would run the following command:
ssh -i /path/to/private/key ec2-user@ec2-<blah blah>.compute-1.amazonaws.com.
to get more details of your issue you can try -v flag for verbose.
ssh -v -i /path/to/private/key ec2-<blah blah>.compute-1.amazonaws.com.
Relevant content
- asked 2 years ago
- asked 5 years ago
- AWS OFFICIALUpdated 3 months ago
- AWS OFFICIALUpdated a year ago
- AWS OFFICIALUpdated 2 years ago
- AWS OFFICIALUpdated 8 months ago