新加坡区域新启动免费层Linux实例SSH密钥连接失败求助
Hey Eleena, sorry to hear you're stuck with SSHing into your new Singapore region free-tier Linux instance—let's work through this step by step to fix that Permission denied (publickey,gssapi-keyex,gssapi-with-mic) error!
Common Fixes to Try
Lock down your local PEM file permissions first
Linux is super strict about private key security—if your PEM file has too open permissions (like readable by other users), SSH will flat-out reject it. Run this on your local machine (swapyour-key.pemwith your actual key filename):chmod 600 your-key.pemThis restricts access to only you, which is a non-negotiable requirement for SSH to use the key.
Double-check your SSH command syntax (especially the username)
Different Linux distros use different default usernames for cloud instances—using the wrong one will trigger a permission error. Here are the most common defaults:- Amazon Linux 2/2023:
ec2-user - Ubuntu:
ubuntu - Debian:
adminordebian - RHEL/CentOS:
ec2-user(orrootin rare cases)
Your command should look like this (fill in your details):
ssh -i "your-key.pem" correct-username@your-instance-public-ipYou can also use the instance's public DNS instead of the IP if that's easier.
- Amazon Linux 2/2023:
Make sure your instance's security group allows SSH traffic
Even with a perfect key, if the security group blocks port 22, you can't connect. Head to your cloud console:- Go to your instance's details page
- Click on the security group linked to your instance
- Check the inbound rules—there should be a rule for
SSH (22)that allows traffic from your public IP (use the "My IP" option in the console to auto-fill this, or use0.0.0.0/0temporarily for testing—just remember to tighten it later) - If no such rule exists, add it right away.
Confirm you're using the exact key pair you selected at launch
It's easy to mix up key pairs when spinning up a new instance. Double-check:- In the instance details, look for the "Key pair name" field
- Compare it to the name of your PEM file—if they don't match, you have two options:
- Terminate this instance and launch a new one with the correct key pair (the simplest route for free-tier instances)
- Go through the more complex process of injecting a new key pair into the running instance (not recommended unless you're comfortable with cloud instance recovery)
Give the instance a minute to fully initialize
Newly launched instances often take 2-5 minutes to finish booting up and configure SSH services. If you tried connecting immediately after launch, wait a bit and try again.Debug with verbose SSH output
If none of the above works, run the SSH command with-vto get detailed logs about where the connection is failing:ssh -v -i "your-key.pem" correct-username@your-instance-public-ipLook for lines like "Offering public key" or "Server refused our key"—these will point you to whether the key is being recognized or if there's another underlying issue.
Hope one of these fixes gets you connected smoothly!
内容的提问来源于stack exchange,提问作者Eleena jose

