AWS SSH connection error: Permission denied (publickey)

后端 未结 9 1638
隐瞒了意图╮
隐瞒了意图╮ 2020-12-07 22:58

Im trying to connect to my EC2 instance with SSH and Iḿ getting crazy. I have read this post and tried all user combinations:

AWS ssh access 'Permission denied (

相关标签:
9条回答
  • 2020-12-07 23:33

    One easy way to get this error is a corrupt .pem file.

    For example, if the last line is missing, you get "missing begin marker".

    Make sure the .pem ends with:

    -----END RSA PRIVATE KEY-----

    0 讨论(0)
  • 2020-12-07 23:34

    While not specific to AWS, this unhelpful error message

    debug1: key_parse_private2: missing begin marker

    will occur under a handful of obscure scenarios, such as when the ownership (or the permissions) on the SSH user's home directory are incorrect on the remote machine.

    The best way to troubleshoot this and similar obscure messages is to examine the authorization log on the remote machine, provided you have access, as it will usually pinpoint the problem. On Debian and Ubuntu systems, this is most easily accomplished with tail (use sudo as appropriate):

    tail -f -n 80 /var/log/auth.log

    In my particular case, I found

    Authentication refused: bad ownership or modes for directory /var/www

    Perfectly accurate and concise: the owner:group was set to daemon:daemon when it should have been www-data:www-data (this was on a Ubuntu machine that must have had some other web-server installed in the past).

    0 讨论(0)
  • 2020-12-07 23:39

    Try this steps:

    ssh-keygen -R 54.72.242.0
    
    sudo chmod 600 ec2-key-pair.pem
    

    and then:

    ssh -i ec2-key-pair.pem ec2-user@ec2-54-72-242-0.eu-west-1.compute.amazonaws.com
    
    0 讨论(0)
  • 2020-12-07 23:43

    Logging in as "admin" worked for me. Based on your instance type the login user changes. ec2-user or ubuntu or in my case admin. ssh -v -i ./my_key_file.pem admin@ec2-11-222-333-44.compute-1.amazonaws.com

    Also ensure the permission for the pem file is 600 chmod 600 ./my_key_file.pem

    0 讨论(0)
  • 2020-12-07 23:44

    Yes, indeed quite misleading message. In my case I used wrong key for instance.

    We had need to removed key pair and created new one, except that our instance kept using old one(because you can't do it that easy).

    The error message was the same so it's worth to check key name in your aws panel of instance match the key pair that you use in key paris.

    0 讨论(0)
  • 2020-12-07 23:48

    Many problems may cause the connectivity issue: Please review the following settings:

    1. AWS security group settings and check the ssh port 22 policy
    2. Check the firewall setting you are using in your lan connection
    3. Generate the ssh-keygen on your local machine and add to aws linux server for future safety.
    4. Regenerate the new ssh key in the panel.
    5. Check your ipblacklist on mxtoolbox if you are using firewall on the aws linux server.

    Please try above all if possible to overcome the error. Let me know if its working or not.

    0 讨论(0)
提交回复
热议问题