Skip to content

Instantly share code, notes, and snippets.

@arupgsh
Forked from jaskiratr/chmod-400.cmd
Created April 7, 2024 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arupgsh/896ea53889a5107f14f74d8d3a9c9a84 to your computer and use it in GitHub Desktop.
Save arupgsh/896ea53889a5107f14f74d8d3a9c9a84 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment