Several months ago, my friend decided to stop one of his instances. Before stopping it, he created an image of its used to launch it again in the future.
Today, I launch the new instance again from that image, but I cannot ssh into that new instance while I can still ssh into the his old instance. I use the same key pair and security group as the old instance.
The error is: ssh: connect to host xxx.xxx.xxx.xxx port 22: Connection refused
What are the possible causes and how can I fix them?
Connection refused indicates a network failure when trying to ssh. You shuold make sure your server contains a security group allowing your IP to connect to the server via port 22.
You can resolve the issue by adjusting the permissions of "/var/empty/sshd":
chown root:root /var/empty/sshd
chmod 711 /var/empty/sshd
If it does not solve your issue please share the output of telnet.
Related
I tried to connect to a running ec2 instance with my usual settings, it returns
ssh: connect to host ec2 port 22: Connection timed out
I tried to connect with the built-in "EC2 Instance Connect", to connect directly from the browser with the AWS account, it returns
There was a problem setting up the instance connection An error
occurred and we were unable to connect or stay connected to your
instance. If this instance has just started up, try again in a minute
or two.
The instance was running for weeks, I am the only user with access to the AWS account and the SSH Keys and I didn t change any setting in the last ~3 weeks or restarted it
1st the timeout started ~1 week ago, nand then without any other change, my website (wordpress) suddenly started to show a database connection error (the database in inside the EC2 instance as well)
What I used to connect :
Either
ssh -i "Keys.pem" ec2-user#ec2-[public ip].eu-west-3.compute.amazonaws.com
Or
ssh ec2-user#[public ip] -i "Keys.pem"
Both show the same error. I used the first one several weeks ago and it used to work well
This timeout will be caused by invalid security group rules.
Ensure that the security group rules attached to your instance allow inbound access from the source IP address you're trying to SSH from, the database connection may also be related to this.
If you're connecting using a dynamic public IP address to SSH to your host, you will need to adjust this every time your IP address changes. It might be more appropriate to setup a VPN so that you can connect privately to your host.
I used to be able to connect to my ec2 instance but suddenly I am no longer able to and I do not know why. My security group is the same, allowing ssh from anywhere. I have some information below regarding the errors that I am getting. Please can someone advise?
From FileZilla I am getting:
Error: ssh_init: nodename nor servname provided, or not known
Error: Could not connect to server
From the terminal I am just getting:
ssh: connect to host ec2-xx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com port 22: Connection refused
i have the same issue i did the following troubleshooting steps and it still gives the same
ssh: connect to host [my public DNS] port 22: Connection refused
i checked the key ".pem" file and its correct on the right directory
no code edits as it used to work fine last night and suddenly this error appeared
i went to the AWS console, selected the instance , and clicked on connect and copied the SSH command to make sure that no typos , and the command is correct
i tried with -v , still same issue.
tried to reboot the instance , no progress
stop then start the instance , no progress
tried to detach the volum and re attach the volum back , no progress
i changed the instance type from t2.micro to t2.small , no progress
checked the security group , port 22 is assigned to all IPs and no problem with the security group at all as it used to work fine
tried from different computers from different networks, same issue
created new instance , i can access the new one but cant ssh to the old one still
my best guess is that the ssh daemon is not enabled but how to access it if i cant ssh to the instance
I am currently overseas and I am trying to connect to my EC2 instance through ssh but I am getting the error ssh: connect to host ec2-34-207-64-42.compute-1.amazonaws.com port 22: Connection refused
I turned on my vpn to New York but still nothing changes. What reasons could there be for not being able to connect to this instance?
The instance is still running and serving the website but I am not able to connect through ssh. Is this a problem with the wifi where I am staying or with the instance itself?
My debugging steps to EC2 connection time out
Double check the security group access for port 22
Make sure you have your current IP on there and update to be sure it hasn't changed
Make sure the key pair you're attempting to use corresponds to the one attached to your EC2
Make sure your key pair on your local machine is chmod'ed correctly. I believe it's chmod 600 keypair.pem check this
Make sure you're in either your .ssh folder on your host OR correctly referencing it: HOME/.ssh/key.pem
Last weird totally wishy washy checks:
reboot instance
assign elastic IP and access that
switch from using the IP to Public DNS
add a : at the end of user#ip:
Totally mystical debugging sets for 6 though. That's part of the "my code doesn't work - don't know why. My code does work - don't know why." Category
Note:
If you access your EC2 while you are connected to a VPN, do know that your IP changes! So enable incoming traffic from your VPN's IP on your EC2 security group.
In AWS, navigate to Services > EC2.
Under Resources, select Running Instances.
Highlight your instance and click Connect.
In Terminal, cd into the directory containing your key and copy the command in step 3 under "To access your instance."
In Terminal, run: ssh -vvv -i [MyEC2Key].pem ec2-user#xx.xx.xx.xx(xx.xx.xx.xx = your EC2 Public IP) OR run the command in the example under step 4.
Just check if your public ip that you get when you are on VPN is configured as a source address in the SG inbound entry that opens up port 22.
You can check your ip using https://www.google.co.in/search?q=whats+my+ip, when connected to your VPN.
I tried everything in this and several other answers, also in some aws youtube videos. Lost perhaps five hours over a few sessions trying to solve it and now finally..
I was getting the exact same error message as the OP. I even rented another EC2 instance in a nearer data centre for twenty minutes to see if that was it.
Then I thought it might be the router or internet provider in the guest house where I am staying. Had already noticed that some non-mainstream news sites had been blocked - and that was it!
You can check if the router is blocking port 22:
https://superuser.com/questions/1336054/how-to-detect-if-a-network-is-blocking-outgoing-ports
cardamom#neptune $ time nmap -p 22 portquiz.net
Starting Nmap 7.70 ( https://nmap.org ) at 2021-02-03 20:43 CET
Nmap scan report for portquiz.net (27.39.379.385)
Host is up (0.028s latency).
rDNS record for 27.39.379.385: ec2-27-39-379-385.eu-west-3.compute.amazonaws.com
PORT STATE SERVICE
22/tcp closed ssh
Nmap done: 1 IP address (1 host up) scanned in 0.19 seconds
real 0m0,212s
user 0m0,034s
sys 0m0,017s
Then, the question of why someone would want to block the ssh port 22 is addressed in at length here:
https://serverfault.com/questions/25545/why-block-port-22-outbound
Had the same problem after creating some instances on a new VPC. (If internet SSH worked before this solution may not work for you)
When creating a new VPC, make sure you create an internet gateway (VPC -> Internet Gateways)
And also make sure that your VPC's routing table (VPC -> Route Tables) has an entry which redirects all IPs (or just your IP) to the internet gateway you just created.
For me, it was because of this:
NOT ec2-user#xx.xx.xx.xx
BUT THIS =>>> ubuntu#xx.xx.xx.xx
Watch the image of EC2 instance!
Instead of
ssh -i "key.pem" ubuntu#ec2-161-smth.com
use
ssh -i "key.pem" ec2-user#ec2-161-smth.com
FileZilla throws errors when trying to connect to AWS instance via SFTP mode. Instance is running on Ubuntu 13.10.
Error: Connection refused
Error: Could not connect to server
Connection params:
Host: XX.XX.X.XXX
Username: ubuntu
Port: 22
Problem solved: seems that my instance was glitchy. Terminated the old one and create new. Working now.
By default the Security groups keeps all the ports closed. You need to enable the SFTP port in the security group: Amazon EC2 Security Groups
Another, thing is to ensure an SFTP server is running on the instance (you can login/SSH to the instance and try connecting SFTP locally and check this).
Open the appropriate inbound port in your Security Group as described here.
Import the .pem key pair associated to your EC2 instance into FileZilla.
The way to access your instance is described here.
I am having some issues with connecting to ubuntu instance in amazon. I can connect to the default instance with default AMI installation. But when I select ubuntu, I cannot ssh into it.
It says operation timeout. I have tried instantiating other instances rebooting changing key pairs etc.
ssh -i mykey.pem ubuntu#ec2-54-203-164-37.us-west-2.compute.amazonaws.com
ssh: connect to host ec2-54-203-164-37.us-west-2.compute.amazonaws.com port 22: Operation timed out
The strange thing when I stop the instance, then only the ssh command connects and says the are you sure you want to verify the fingerprint thing.
I can easily log into the micro instance with the default AMI installation
I have added the ssh port in the security group as well
Have you tried connecting via Putty ,just use a ppk file and please check once
also you can add ICMP to your Security Group and check for ping resposnses
Regards
Devashish