Created
September 24, 2020 09:29
-
-
Save devashishpatil56/9a3ef4b64ed811f09652cc7bfb4da0d7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$path = "Path\to\your\ssh_key.pem" | |
#Get current ACL to file/folder | |
$acl = Get-Acl $path | |
#Disable inheritance and remove inherited permissions | |
$acl.SetAccessRuleProtection($true,$false) | |
#Remove all explict ACEs | |
$acl.Access | ForEach-Object { $acl.RemoveAccessRule($_) } | |
#Create ACE for owner with read-access. You can replace $acl.Owner with $env:UserName to give permission to current user | |
$ace = New-Object System.Security.AccessControl.FileSystemAccessRule -ArgumentList $acl.Owner, "Read", "Allow" | |
$acl.AddAccessRule($ace) | |
#Save ACL to file/folder | |
Set-Acl -Path $path -AclObject $acl |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment