简体   繁体   中英

AWS: can't connect to Amazon Linux EC2 instance

I'm working with AWS, I have an EC2 instance (Amazon Linux) but I can't connect to it, I've checked all VPC parameters and they are enabled as well as the instance, but when I try to connect it using EC2 Instance Connect I get this message:

无法连接

I'm using the default user account, also I generated a key pair however I'm getting this other message:

sshcantconnect

Also, session manager can't connect.

So my question is: what settings do I need to update or check in order to connect to my EC2 instance?

Thanks a lot for your comments.

There are multiple ways to login to an Amazon EC2 instance.

SSH

Your screenshot shows that you are wanting to login via SSH, but it is saying that no Keypair was selected when the instance was launched. Therefore, this option is not available for you.

EC2 Instance Connect

If you ware wanting to login to the Amazon EC2 instance using EC2 Instance Connect and you are experiencing connectivity problems, then make sure that your Security Group permits Inbound access on port 22 from the IP address range of the EC2 Instance Connect service (not your own IP address).

This is because the EC2 Instance Connect client on your computer connects to AWS on port 443 (as a web connection), and then the traffic goes from the EC2 Instance Connect service to the EC2 instance as a normal SSH connection on port 22. Therefore, the Security Group needs to permit Inbound connections on port 22 from the IP address range of the EC2 Instance Connect service (or you can be lazy and just select 0.0.0.0/0 , but that is a lower level of security).

You can find the IP address ranges for AWS services at: AWS IP address ranges - AWS General Reference

Please note that your EC2 instance must be in a public subnet and you must connect via a public IP address .

AWS Systems Manager Session Manager

The Session Manager connects in a totally different way, without using SSH. It requires an Agent to be installed on the EC2 instance (and it is there by default if you launched from an Amazon Linux AMI). This Agent then creates an Outbound connection to AWS, so it does not require any Inbound security rules (but it does require the default "Allow All" Outbound rule).

Session Manager has the additional benefit that it allows you to connect to EC2 instances that are in private subnets , as long as the EC2 instance can access the Internet via a NAT Gateway or if the VPC has a VPC endpoint for Systems Manager.

I think you may be using the wrong key pair to connect the instance.

You can follow the below link to connect the instance via ssh.

https://thetechnicaldiaries.com/aws/how-to-connect-to-aws-ec2-instance-via-ssh-putty-from-windows-using-a-key-pair/

If you want to check the process of generating key-pair, you can follow the below article, in this, a full process of generating key-pair and launching the instance is shown step by step.

https://thetechnicaldiaries.com/aws/how-to-create-aws-ec2-instance-step-by-step-in-2022/

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