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

Mobaxterm连接AWS Linux实例遇Permission Denied (Publickey)错误求助

Troubleshooting Permission Denied (Publickey) for AWS Linux via MobaXterm

Hey Dave, sorry to hear you're stuck with this frustrating SSH error when trying to connect to your AWS instance through MobaXterm. You already checked file permissions on your Mac—good call, since that's a common gotcha—but let's walk through more targeted fixes to get you logged in:

1. Confirm the Key Pair is Linked to Your AWS Instance

  • First, double-check that the private key you're using is exactly the one you specified when launching the instance. AWS doesn't allow arbitrary keys to access instances after creation. If you mixed up keys, you can stop the instance (make sure to back up any critical data first!), then go to the AWS Console → Instance Details → Actions → Security → Change Key Pair to associate the correct one.
  • Verify your key file format: AWS provides PEM files by default, and MobaXterm supports both PEM and PPK. If you converted your PEM to PPK, use MobaXterm's built-in PuTTYgen to re-convert it (Load the PEM, then Save private key) to rule out conversion errors.

2. Fix MobaXterm SSH Session Configuration

  • Double-check the default username: AWS AMIs use different default users:
    • Amazon Linux 2/2023: ec2-user
    • Ubuntu: ubuntu
    • CentOS/RHEL: centos or ec2-user
    • Debian: admin or debian
      Using the wrong username will trigger a public key denial even if your key is correct.
  • In your MobaXterm SSH session settings, go to Advanced SSH settings and confirm the Private key field points to your private key file (not the .pub public key).

3. Verify Instance-side SSH and Firewall Settings

  • Try logging in via EC2 Instance Connect (from the AWS Console) first. If this works, the instance's SSH service is healthy, and the issue is local. If it fails, the problem is on the instance itself:
    • Once logged in (via Instance Connect), check /etc/ssh/sshd_config:
      • Ensure PubkeyAuthentication yes is uncommented (public key auth must be enabled)
      • Confirm AuthorizedKeysFile points to the correct path (default is ~/.ssh/authorized_keys)
      • Make sure PasswordAuthentication no isn't conflicting if you accidentally tried password login (though this shouldn't affect key-based auth)
  • Check your AWS Security Group: Ensure the inbound rule allows SSH (port 22) from your local IP address. You can temporarily set it to 0.0.0.0/0 for testing, but remember to lock it back to your IP for security.

4. Recheck Local Key File Permissions (Even if You Did This Before)

  • On your Mac, run these commands to ensure strict permissions (SSH rejects keys with overly open permissions):
    chmod 700 ~/.ssh
    chmod 600 ~/.ssh/your-key.pem
    
  • Also, make sure the parent directory of ~/.ssh (your home folder) has permissions no looser than chmod 755—777 will break SSH key validation.

5. Enable SSH Debug Mode to Pinpoint the Issue

  • Open a local terminal in MobaXterm and run this command to get detailed debug output:
    ssh -v -i /path/to/your-key.pem your-username@instance-public-ip
    
    Look for lines like "Offering public key" or "Server refused our key"—this will tell you if the key isn't being loaded, if the server doesn't recognize it, or if there's a username mismatch.

Hope one of these steps gets you connected smoothly! If you can share the debug output from the -v command, we can narrow it down even further.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.19 08:44:00