Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unable to connect to EC2 Linux instance from Windows 10 CMD using ssh

I have a running EC2 instance that is running Linux OS(Amazon Linux AMI release 2018.03) on it.

Given that Windows 10 has SSH client available in the command prompt, I was trying to SSH into my EC2 instance using the SSH private key(.pem file) provided by AWS as a key pair during the setup of the EC2 instance.

The command I am using on cmd is :

ssh -i private_key.pem [email protected]

Here private_key.pem is the name of the private key file provided by AWS.

But I keep getting the error:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions for '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 "private_key.pem": bad permissions
[email protected]: Permission denied (publickey).

Some things I would like to clarify:

  1. There are similar questions on StackOverflow. Those questions actually involve trying to connect to the EC2 instance from a host that is running MacOS/Linux(any UNIX based OS). In my case I am trying to connect from Windows 10 host using command prompt.

  2. In answer to such other questions as discussed in (1), people have suggested trying to change the file permission of the private key file(.pem) file to read-only(chmod 444 file.pem). In response, I tried making my .pem file as read-only from the file properties in my Windows. This did not help. I keep getting the same error.

  3. I am able to connect to other remote Linux hosts from my Windows 10 cmd, which suggests there is probably no problem with my Windows 10 SSH client.

  4. I know this connection can be made easier by using Putty instead of CMD, but that is not what this question is about. Just assume because of some constraints I cant use Putty.

Any help would be appreciated.

like image 597
DockYard Avatar asked Apr 11 '20 19:04

DockYard


1 Answers

In Windows 10, locate the .pem file in question and right-click on it.

From Properties-->Security--> Advanced:

  1. Make sure your user is the owner of the file
  2. Give Read&Execute permissions for your user specifically,
    while removing all other permissions on the file for other users or groups.

enter image description here

like image 105
Adi Dembak Avatar answered Sep 30 '22 19:09

Adi Dembak