5

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 [email protected]

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.

3
  • 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
    Commented Dec 27, 2017 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. Commented Mar 27, 2021 at 21:24
  • If you are using WSL, this answer might help you: stackoverflow.com/a/75001941/12326605
    – Arpit Jain
    Commented Nov 29, 2023 at 5:46

1 Answer 1

8

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
0

Not the answer you're looking for? Browse other questions tagged or ask your own question.