AWS EC2 instance SSH Connection timed out for port 22
In this post I'll describe one of the connectivity issue that I faced while working with AWS EC2 instance. Below is the problem summary, cause and solution. Let's get started...
Problem
I have created an EC2 Ubuntu Linux instance and configured the same my own. However, I have installed some container application on the same but during the work all of a sudden the SSH connection lost. Now, when I tried to get the connection again , it says-
ssh -L 5901:localhost:5901 -I ssh-key.pem ubuntu@ec2-13-xxx-xxx-139.ap-south-1.compute.amazonaws.com
connection timeout for port 22
Cause
There could be multiple reasons of the same like, inbound rule changes for port 22, firewall turned on, Security group changes etc. In my case it was 'firewall turned on'.
Solution
So how should I go to turn off the firewall without native ssh connection which I do over terminal/putty? The answer is through other was utilities like-
- Browser based SSH connection
- AWS Systems Manager
- .....
In my case, I have used AWS Systems manager since browser based SSH wasn't working in my machine. Following are the steps I used to connect my linux instance via AWS Systems Manager-
- Go to AWS Systems Manager- https://ap-south-1.console.aws.amazon.com/systems-manager
- If you have not configured Systems Manager -> Click on Get Started with Systems Manager
- In my case I have already configured the same so I have Edit option visible there, you might been to configure the same with default options or change as per your requirement. I have configured with the defaults.
- Now we re ready with Systems Manager configuration. So, in order to get SSH connection go back to https://ap-south-1.console.aws.amazon.com/systems-manager , scroll down and find the section so called Remote Connect and Click on Explore Session Manager.
- Next > Click on Start Session Button
- Next > Select the instance and Start Session
- Next > a new tab will open in browser with SSH connection
So now we need to check the firewall status-
$ sudo ufw status
$ active
Since firewall is turned on so we need to disable it-
$ sudo ufw disable
Check the status again
$ sudo ufw status
$ inactive
Next > Terminate the session and take normal ssh connection from terminal and it should work now-
ssh -L 5901:localhost:5901 -I ssh-key.pem ubuntu@ec2-13-xxx-xxx-139.ap-south-1.compute.amazonaws.com Welcome to Ubuntu 18.04.4 LTS (GNU/Linux 5.3.0-1017-aws x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Wed May 20 08:21:37 UTC 2020
System load: 0.0 Processes: 263
Usage of /: 85.1% of 29.02GB Users logged in: 1
Memory usage: 42% IP address for eth0: 172.31.33.26
Swap usage: 0% IP address for docker0: 172.17.0.1
=> / is using 85.1% of 29.02GB
* MicroK8s passes 9 million downloads. Thank you to all our contributors!
https://microk8s.io/
* Canonical Livepatch is available for installation.
- Reduce system reboots and improve kernel security. Activate at:
https://ubuntu.com/livepatch
0 packages can be updated.
0 updates are security updates.
Last login: Wed May 20 07:51:18 2020 from 157.38.98.218
ubuntu@ip-172-31-33-26:~$
https://aws.amazon.com/premiumsupport/knowledge-center/ec2-linux-resolve-ssh-connection-errors/
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-console.html
https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-getting-started.html
https://linuxize.com/post/how-to-disable-firewall-on-ubuntu-18-04/
Good Post. I like your blog. Thanks for Sharing.
ReplyDeleteDevOps Training
DevOps Online Training
DevOps Training in Ameerpet
Nice Blog!! It is very helpful and very informative and I really learned a lot from it.
ReplyDeleteDevOps Training
DevOps Online Training
which is very useful to new learners and professionals DevOps Training in Bangalore | Certification | Online Training Course institute | DevOps Training in Hyderabad | Certification | Online Training Course institute | DevOps Training in Coimbatore | Certification | Online Training Course institute | DevOps Online Training | Certification | Devops Training Online
ReplyDeleteAn awesome blog for the freshers. Thanks for posting this information.
ReplyDeleteWorkday Studio Training
Workday Studio Online Training
It is amazing to visit your site. Thanks for sharing this information, this is useful to me...
ReplyDeleteWorkday Studio Online Training India
Workday Studio Online Training Hyderabad
Thanks for sharing such a good and informative content to all of us
ReplyDeleteWorkday Training Online
Workday Training
Those guidelines additionally worked to become a good way to recognize that other people online have identical fervor like mine to grasp a great deal more around this condition. and I could assume you are an expert on this subject. Same as your blog i found another one Sell On Amazon .Actually I was looking for the same information on internet for Sell On Amazon and came across your blog. I am impressed by the information that you have on this blog. Thanks a million and please keep up the gratifying work.
ReplyDeleteNice Post. I like your blog. Thanks for Sharing.
ReplyDeleteDevOps Training
DevOps Online Training
This post is so usefull and informative.Keep updating with more information...
ReplyDeleteBenefits Of AWS
Advantages Of AWS
This comment has been removed by a blog administrator.
ReplyDeleteThis comment has been removed by a blog administrator.
ReplyDeleteAPTRON provides the best AWS Institute in Noida. We provide complete hands-on training and flexible class schedules with students’ time.
ReplyDelete