3

I am having problems with my key pairs and likely SSH permissions as I can no longer SSH into my EC2 instances.

I execute the following command:

ssh -i /Users/Matt/Downloads/private-key.pem ec2-user@XX.XXX.XXX.XXX

Keep in mind I just created this key pair in the AWS Management Console which downloaded the key .pem file to my downloads file. I then get the following error message after replying "yes" to continue connecting.

Failed to add the host to the list of known hosts 
(/Users/Matt/.ssh/known_hosts).
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0644 for '/Users/Matt/Downloads/private-key.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
Load key "/Matt/Downloads/private-key.pem": bad permissions
Permission denied (publickey).

Ok so I've spent the better part of a day troubleshooting this and have tried retrieving the pub file, importing that as a key pair, etc. and still I get permission denied (public key) or am prompted for a non-existent instance associated password. I am fairly certain this must be an issue with my own SSH permissions but I am lost.

This is what I get in the terminal after an ssh -v

 usage: ssh [-XXXXXXXXXXXXXXX] [-b bind_address] [-c cipher_spec]
       [-D [bind_address:]port] [-E log_file] [-e escape_char]
       [-F configfile] [-I pkcs11] [-i identity_file]
       [-L [bind_address:]port:host:hostport] [-l login_name] [-m 
 mac_spec]
       [-O ctl_cmd] [-o option] [-p port]
       [-Q cipher | cipher-auth | mac | kex | key]
       [-R [bind_address:]port:host:hostport] [-S ctl_path] [-W host:port]
       [-w local_tun[:remote_tun]] [user@]hostname [command]

Any help would be sincerely appreciated.

  • SO is for programming questions, not questions about using or configuring Linux. ServerFault,com, SuperUser.com or unix.stackexchange.com would be better places for questions like this. – Barmar Dec 27 '17 at 20:16
  • Check for the permissions of your pem file. it should be 400 as explained in below answer. But aslo make sure it is owned by your current system user. – Alankar More Mar 27 '21 at 21:24

1 Answers1

7

The answer - FYI - is that once you've downloaded your .pem file you simply to run the following command and than you'll be able to SSH into your instance.

chmod 400 /Users/Matt/Downloads/private-key.pem