Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pem file permissions on Bash on Ubuntu on Windows

I am attempting to login to my box using my .pem file however I get the error

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@         WARNING: UNPROTECTED PRIVATE KEY FILE!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
Permissions 0555 for './arete-server.pem' are too open.
It is required that your private key files are NOT accessible by others.
This private key will be ignored.
bad permissions: ignore key: ./arete-server.pem
Permission denied (publickey).

chmod 400 doesn't work on Bash on Ubuntu on Windows and the best permissions I can give it is -r-xr-xr-x

Any idea how to get permissions to a point where I can use this pem file?

like image 237
Chris Avatar asked Sep 09 '16 04:09

Chris


People also ask

How do I give permission to Ubuntu from terminal?

Type “sudo chmod a+rwx /path/to/file” into the terminal, replacing “/path/to/file” with the file you want to give permissions to everyone for, and press “Enter.” You can also use the command “sudo chmod -R a+rwx /path/to/folder” to give permissions to the selected folder and its files.

How do I change file permissions in Ubuntu WSL?

You can configure your file permissions inside of your Windows drives using the mount options in wsl. conf. The mount options allow you to set umask , dmask and fmask permissions masks. The umask is applied to all files, the dmask is applied just to directories and the fmask is applied just to files.


3 Answers

On WSL, chmod donesn't work on NTFS partitions used by Windows. You need to move your .pem file to a partition in Linux container (for example the home folder), then chmod 400 will work.

  1. Navigate to a NTFS folder, example: cd /mnt/c/keyfiles
  2. Move .pem file to your home folder: mv key.pem ~
  3. Navigate to your folder: cd ~
  4. Apply the permission: chmod 400 key.pem
like image 132
ussantos Avatar answered Oct 24 '22 02:10

ussantos


sudo ssh -i mykey.pem ec2-user@ip works for me

like image 6
beewest Avatar answered Oct 24 '22 04:10

beewest


use PowerShell:

  1. icacls.exe key.pem /reset
  2. icacls.exe key.pem /grant:r "$($env:username):(r)"
  3. icacls.exe key.pem /inheritance:r
like image 2
sandyiit Avatar answered Oct 24 '22 03:10

sandyiit