EC2 Instance Connect from the browser will not open an SSH session
Host key validation failed for EC2 Instance ConnectShort answer
Browser-based EC2 Instance Connect needs five things at once: a fresh host key in the AWS database, a current agent package, port 22 open to the EC2 Instance Connect prefix list, a public address with a route (or an Instance Connect Endpoint), and a browser that can reach the proxy on port 443.
Fix it fast
1Find out which cause you have
Log in to the same instance with your normal key pair. If that works, the instance and its network are fine and the fault is in the Instance Connect pieces below. If it does not, fix plain SSH first.
ssh -i my_ec2_private_key.pem ubuntu@ec2-a-b-c-d.us-west-2.compute.amazonaws.com2Match what you see, then jump to its fix
- 1
Host key validation failed for EC2 Instance ConnectThe instance host keys were rotated and AWS still holds the old onesFix - 2
Any connection error on Ubuntu with Instance Connect, and no host key messageThe ec2-instance-connect package on an Ubuntu instance is out of dateFix - 3
The console session hangs, then fails, while SSH from your own IP worksThe security group does not allow SSH from the EC2 Instance Connect serviceFix - 4
Connection fails for a private-subnet instance or one with no public IPv4 or IPv6 addressThe instance has no public address, or its subnet has no route to the internetFix - 5
The page cannot open the session even though the instance and security group look rightYour browser cannot reach the Instance Connect proxyFix
- 1
What does the error look like?
Host key validation failed for EC2 Instance Connect
Cause 1 of 5
The instance host keys were rotated and AWS still holds the old ones
1Check
AWS keeps a trusted host key database. If you regenerate the instance's SSH host keys, the new keys are not uploaded on their own, so the browser client's check fails.
ls /usr/share/ec2-instance-connect/ /opt/aws/bin/ 2>/dev/null2Fix
Log in with your key pair and run the eic_harvest_hostkeys script. It is in /usr/share/ec2-instance-connect/ on Ubuntu and in /opt/aws/bin/ on Amazon Linux 2. A successful run prints nothing.
cd /usr/share/ec2-instance-connect/
./eic_harvest_hostkeys3Verify
Open the browser client again; the host key check now passes.
# EC2 console > Instances > select instance > Connect > EC2 Instance Connect > ConnectConfirmed by docs.aws.amazon.com
Cause 2 of 5
The ec2-instance-connect package on an Ubuntu instance is out of date
1Check
The AWS page lists an old ec2-instance-connect package as a possible cause on Ubuntu.
dpkg -l ec2-instance-connect2Fix
Connect another way (your key pair works) and update the packages on the instance.
sudo apt update && sudo apt upgrade3Verify
Try the browser connection again.
dpkg -l ec2-instance-connectConfirmed by docs.aws.amazon.com
Cause 3 of 5
The security group does not allow SSH from the EC2 Instance Connect service
1Check
From the console, the traffic that reaches the instance comes from the EC2 Instance Connect service, not from your computer. AWS manages its addresses in a prefix list named com.amazonaws.<region>.ec2-instance-connect (IPv4) and com.amazonaws.<region>.ipv6.ec2-instance-connect (IPv6). Your own-IP rule for port 22 does not cover it.
aws ec2 describe-security-groups --group-ids sg-1234567890abcdef02Fix
Add an inbound SSH rule whose source is that prefix list. In the console, pick the prefix list from the Source field. With the CLI you need the prefix list ID (shown in the VPC console under Managed prefix lists).
aws ec2 authorize-security-group-ingress \
--group-id sg-1234567890abcdef0 \
--ip-permissions 'IpProtocol=tcp,FromPort=22,ToPort=22,PrefixListIds=[{PrefixListId=pl-0123456789abcdef0}]'3Verify
Reconnect from the EC2 console.
aws ec2 describe-security-groups --group-ids sg-1234567890abcdef0Confirmed by docs.aws.amazon.com
Cause 4 of 5
The instance has no public address, or its subnet has no route to the internet
1Check
To connect over the internet, the instance needs a public IPv4 or IPv6 address and must sit in a public subnet with a route to the internet. A default public subnet routes IPv4 only, not IPv6.
aws ec2 describe-instances --instance-id i-1234567890abcdef02Fix
Give the instance a public address and a route, or use an EC2 Instance Connect Endpoint, which lets you reach an instance over SSH even when it has no public IPv4 or IPv6 address.
# EC2 console > Instances > Connect > EC2 Instance Connect Endpoint tab3Verify
Connect again with the method you chose.
aws ec2 describe-instances --instance-id i-1234567890abcdef0Confirmed by docs.aws.amazon.com
Cause 5 of 5
Your browser cannot reach the Instance Connect proxy
1Check
The console opens a WebSocket on port 443 to a Region-specific proxy, for example prod.us-east-1.oneclickv2-proxy.ec2.aws.dev for US East (N. Virginia). A firewall or VPN that blocks it makes the connection fail.
curl -sS -o /dev/null -w '%{http_code}
' https://prod.us-east-1.oneclickv2-proxy.ec2.aws.dev2Fix
Allow outbound HTTPS and WebSocket to that endpoint for your Region, or pause the VPN or proxy and try again.
# ask the network owner to allow prod.<region>.oneclickv2-proxy.ec2.aws.dev on port 4433Verify
Open the browser client again.
# EC2 console > Instances > Connect > EC2 Instance Connect > ConnectConfirmed by docs.aws.amazon.com
How do I stop it coming back?
- If you ever regenerate host keys, run eic_harvest_hostkeys straight after.
- Keep the Instance Connect prefix-list rule in the security group that your servers share, so new instances work at once.
- Keep one working SSH key pair route, so a fault in the browser path never locks you out.
- Update the instance packages on a regular schedule.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
- Dispatch ProA real-time logistics platform: Flutter apps, Spring Boot services and a Kafka event pipeline on AWS.
- RaheebA consumer app shipped to both stores from one Flutter codebase on a .NET and Azure back end.
- Loade DriverThe driver side of a delivery platform: live jobs, routing and earnings, past 5K Google Play downloads.
Related fixes
Servers
ssh to an EC2 instance hangs and ends in Connection timed out
Network error: Connection timed out
A timeout means your packets never got an answer, so this is a network path problem, not a key problem.
4 causes, each with a fixServers
SSH to EC2 fails: refused key, or told to log in as ec2-user not root
Server refused our key
Almost always the instance is fine and the login is not.
4 causes, each with a fixServers
Apache has a certificate, but https:// does not open
No line with :443 in the output of ss -ltnp
HTTPS needs four things at once: mod_ssl loaded, Apache listening on 443, a virtual host on 443 with SSLEngine on, and a firewall that lets 443 in.
4 causes, each with a fixServers
AWS CLI says you must specify a region
You must specify a region. You can also configure your region by running "aws configure".
The AWS CLI sends every request to one region and has none to use.
4 causes, each with a fixServers
sam local fails: Running AWS SAM projects locally requires Docker
Cannot connect to the Docker daemon. Is the docker daemon running on this host?
sam local start-api and sam local invoke run your function inside a Docker container, so SAM stops if it cannot talk to Docker.
3 causes, each with a fixServers
git clone from CodeCommit over HTTPS returns 403
aws codecommit credential-helper $@ get: aws: command not found
A 403 from CodeCommit over HTTPS usually means Git sent the wrong credentials, not none.
5 causes, each with a fix