Skip to content

Instantly share code, notes, and snippets.

@devashishpatil56
Created September 24, 2020 09:29
Show Gist options
  • Save devashishpatil56/9a3ef4b64ed811f09652cc7bfb4da0d7 to your computer and use it in GitHub Desktop.
Save devashishpatil56/9a3ef4b64ed811f09652cc7bfb4da0d7 to your computer and use it in GitHub Desktop.
$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