Skip to content

Instantly share code, notes, and snippets.

@jaskiratr
Created June 29, 2018 01:03
Show Gist options
  • Save jaskiratr/cfacb332bfdff2f63f535db7efb6df93 to your computer and use it in GitHub Desktop.
Save jaskiratr/cfacb332bfdff2f63f535db7efb6df93 to your computer and use it in GitHub Desktop.
Set permission of file equivalent to chmod 400 on Windows.
# Source: https://stackoverflow.com/a/43317244
$path = ".\aws-ec2-key.pem"
# Reset to remove explict permissions
icacls.exe $path /reset
# Give current user explicit read-permission
icacls.exe $path /GRANT:R "$($env:USERNAME):(R)"
# Disable inheritance and remove inherited permissions
icacls.exe $path /inheritance:r
@54keesh
Copy link

54keesh commented Feb 2, 2024

keep in mind that although both of these solutions perfectly work but itll still have owner group and other read permissions if sshing via wsl and might still give bad permisiions. so you need to ssh explicitly via powershell not wsl

@Hassan829
Copy link

This works Thanks alot

@yzuriaw
Copy link

yzuriaw commented Mar 21, 2024

Legend

@tonytwei
Copy link

thanks

@ShreePatil19
Copy link

Thank you so much this had been buggin me for quite a while...

@pierangelo
Copy link

In windows 10, using the commands listed above I ran into the following error:

Invalid parameter "$($env:username):(r)"

so, I changed it by "%username%:(r)" and it worked properly. Thanks a lot!!!

thanks!

@intothedeep
Copy link

Thank you

@SteverRobinson
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment