내용으로 건너뛰기

EC2: Cannot connect anymore via Instance Connect or SSH command line

0

Hello,

Error when connecting via Instance connect:

“Failed to connect to your instance Error establishing SSH connection to your instance. Try again later.”

Error when connecting via command line:

“Permission denied (publickey).”

For more than 4 months I've been able to connect to my EC2 instance without any problem, using SSH on the command line or directly via Instance connect. But for some unknown reason, the connection stopped working yesterday. Even though the instance is still running.

Checks done on my side:

  • The .pem key exists at the path specified in the ssh command and has the correct permissions. I can successfully use the same .pem key to authenticate to another instance.
  • I've not made any change on security groups. Connecting from same IP as usual.
  • Restarting the instance does not solve the problem.
  • Instance is running well.

Is it an usual problem ?

질문됨 2년 전385회 조회

2개 답변
2
수락된 답변

Hello.

Have you checked the EC2 system logs?
There may be some error log output.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/troubleshoot-unreachable-instance.html#instance-console-console-output

Also, settings such as IAM roles are required for EC2, but is it possible to connect with Systems Manager SessinManager?
After connecting to EC2 with SessinManager, check the sshd logs to see if any abnormalities have occurred.
https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/connect-to-an-amazon-ec2-instance-by-using-session-manager.html

전문가

답변함 2년 전

  • Thank you I successfully connected to my instance via Systems Manager. Logs told me "bad ownership or modes for directory /home/ubuntu" when I tried to connect. Now I remember that I've changed owner ship. I revert to initial owner ship, problem solved now ! Thank you again.

2

Hello.

Use EC2 Instance Connect (via AWS Console)

  • Go to the EC2 Dashboard on AWS Console.
  • Select your instance.
  • Click Connect and choose EC2 Instance Connect (no need for a .pem key).
  • Click Connect and see if you can access the instance.

Check Security Group

  • Make sure the Security Group attached to your instance allows port 22 (SSH) for your current IP address.
  • In the EC2 Dashboard, go to Security Groups under Network & Security.
  • Confirm there is an inbound rule for port 22 with your IP (or 0.0.0.0/0 temporarily).

Use AWS Systems Manager (Session Manager) (if IAM permissions allow it)

  • In EC2 Dashboard, click Connect and choose Session Manager.
  • If your instance has the required IAM role, you can use Session Manager to connect without SSH.

https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/connect-to-an-amazon-ec2-instance-by-using-session-manager.html

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/connect-linux-inst-ssh.html#:~:text=If%20you%20receive%20an%20error%20while%20attempting%20to,issues%20connecting%20to%20your%20Amazon%20EC2%20Linux%20instance.

https://medium.com/thecodr/using-an-ssh-client-to-connect-to-an-ec2-instance-65e537df1655

전문가

답변함 2년 전

  • Thank you I successfully connected to my instance via Systems Manager. Ownership was wrong for /home/ubuntu directory.

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.