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 (
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-----
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).
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
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
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.
Many problems may cause the connectivity issue: Please review the following settings:
Please try above all if possible to overcome the error. Let me know if its working or not.