Moonie Asemani
Moonie Asemani

Reputation: 385

Unable to SSH into EC2 Instance pem 'Permissions 0777 for '.ssh/intuit-tke-qe.pem' are too open'

I'm unable to ssh into my EC2 instance, seems to be an issue with the permission level of the ssh .pem file I'm passing to ssh, googling around this seems to be a problem many others have faced but their solutions didn't work for me.

Here is what I tried, someone please help...

Atempt 1:

asemani$ ssh -i ~/.ssh/secure.pem [email protected]

********************************************************************************
This is a private computer system containing information that is proprietary
and confidential to the owner of the system.  Only individuals or entities
authorized by the owner of the system are allowed to access or use the system.
Any unauthorized access or use of the system or information is strictly
prohibited.

All violators will be prosecuted to the fullest extent permitted by law.
********************************************************************************
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0777 for '.ssh/secure.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 ".ssh/secure.pem": bad permissions
Permission denied (publickey).

Attempt 2:

asemani$ chmod 600 ~/.ssh/secure.pem 
asemani$ ls -l ~/.ssh/
total 56
-rw-r--r--  1 asemani  CORP\Domain Users    782 Apr 29 11:14 config
-rw-------@ 1 asemani  CORP\Domain Users   1696 Apr 29 21:32 secure.pem
asemani$ 
asemani$ ssh -i .ssh/secure.pem [email protected]
********************************************************************************
This is a private computer system containing information that is proprietary
and confidential to the owner of the system.  Only individuals or entities
authorized by the owner of the system are allowed to access or use the system.
Any unauthorized access or use of the system or information is strictly
prohibited.

All violators will be prosecuted to the fullest extent permitted by law.
********************************************************************************
Permission denied (publickey).

I don't get the warning anymore but Permission is still denied. I then also tried doing a chmod 400 on the .pem file but that also didn't work. I won't paste that here since that may be overkill.

What is happening here? How can I ssh into my ec2? This should be a simple thing??

Upvotes: 0

Views: 3876

Answers (4)

Leo C
Leo C

Reputation: 22449

Are you able to login as the default user using your pem key? For Ubuntu instances, default user should be ubuntu; for most other instances it should be ec2-user. If you're able to login as the default user, chances are that root isn't allowed for ssh login. To change that, login as the default user and do the following:

# Edit sshd_config and modify 'PermitRootLogin XX' to 'PermitRootLogin yes'
sudo vi /etc/ssh/sshd_config

# Reload sshd configuration
sudo service sshd reload

NOTE: This only serves as a how-to. It's generally not recommended to allow root login over ssh for security reason.

Upvotes: 3

Boullon Daniel
Boullon Daniel

Reputation: 1

to windows users can change the premise of files through wsl doing this:

Edit or create (using sudo) /etc/wsl.conf

[automount]
options = "metadata"

Restart wsl: (powershell) PS Get-Service LxssManager | Restart-Service

and finally, do: chmod 400 key.pem

Upvotes: 0

S Khandelwal
S Khandelwal

Reputation: 191

Change permission to chmod 400 ~/.ssh/secure.pem

Upvotes: 11

K.Land_bioinfo
K.Land_bioinfo

Reputation: 170

You need to launch the instance through your AWS EC2 management console. Once it is launched, copy the public DNS IPv4 and paste it after the linux distribution name being used (e.g. ubuntu@IPv4). Also, make sure you are working in the directory that houses your private access key.

For clarification, once your EC2 instance is launched and you're in the directory that holds your private access key, type in the following in the command-line:

ssh -i private_access_key.pem linux@IPv4

Upvotes: 1

Related Questions