You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

AWS EC2 Linux实例连接失败:无可用认证方法(server sent:publickey)求助

Troubleshooting EC2 Linux Instance Connection Issue: No Supported Authentication Methods

Hey there, let's work through this SSH connection problem you're hitting with your EC2 Linux instance. First off, let's clear up your quick question: a terminated instance has no impact at all on your running instance's connectivity—so that's definitely not the root cause here.

The error message Disconnected : No supported authentication methods available (server sent :publickey) tells us the server only accepts public key authentication, but your client isn't successfully passing that verification. Even though your key pair works for other instances, let's walk through the most common fixes step by step:

  • Fix your .pem key file permissions
    Linux systems are super strict about key file access—if your .pem file is readable by anyone besides you, SSH will reject it immediately. Run this command on your local machine to set the correct permissions:

    chmod 600 /path/to/your/key-pair-file.pem
    
  • Verify your instance's security group allows SSH access
    Double-check your instance's security group inbound rules to make sure TCP port 22 (SSH) is open to your current IP address (you can temporarily use 0.0.0.0/0 for testing, but remember to lock this down to your specific IP later). You can edit this in the EC2 Console under your instance's "Security" tab.

  • Confirm the instance is using the correct key pair
    It's easy to accidentally pick the wrong key pair when launching an instance. Head to the EC2 Console, pull up your instance's details, and check the "Key pair name" field—this must match the name of the .pem file you're using. If it doesn't, you'll either need to launch a new instance with the correct key pair or use EC2 Instance Connect to set up alternative access (if your instance supports it).

  • Double-check your SSH command syntax
    Make sure you're using the right command structure—small typos can break everything:

    ssh -i /path/to/your/key-pair-file.pem ec2-user@<your-instance-public-ip-or-dns>
    

    Note: For non-Amazon Linux distros (like Ubuntu), the default user might be ubuntu instead of ec2-user—but since you mentioned using ec2-user, this should be correct for your setup.

  • Check the SSH server configuration on the instance
    If you can connect via EC2 Systems Manager Session Manager (a great backup option when SSH fails), log into the instance and verify the SSH daemon allows public key auth:

    1. Open the SSH config file:
      sudo nano /etc/ssh/sshd_config
      
    2. Ensure the line PubkeyAuthentication yes is uncommented and set to yes.
    3. Restart the SSH service to apply changes:
      sudo systemctl restart sshd
      

If none of these steps fix the issue, you could try re-downloading your key pair file (to rule out corruption) or checking if your local SSH client has any odd config overrides in ~/.ssh/config.

内容的提问来源于stack exchange,提问作者Cristopher

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 08:15:31