Skip to content

Instantly share code, notes, and snippets.

@SolomonHD
Last active June 29, 2022 14:57
Show Gist options
  • Save SolomonHD/d8b68218c353541c57210bca6cda29d3 to your computer and use it in GitHub Desktop.
Save SolomonHD/d8b68218c353541c57210bca6cda29d3 to your computer and use it in GitHub Desktop.
Powershell Change SSH Key Perms
## This Powershell template sets proper perms for ssh key usage in WSL2. Edit the variables before running
## Requires Powershell 7+!!!
## Set Variables
New-Variable -Force -Name Key -Value "$env:UserProfile\.ssh\key_file_name_here"
New-Variable -Name PERMS -Value "RW"
## Perform Operations,
Icacls $Key /c /t /Inheritance:d && Icacls $Key /c /t /Grant ${env:UserName}:$PERMS && TakeOwn /F $Key && Icacls $Key /c /t /Grant:r ${env:UserName}:$PERMS
Icacls $Key /c /t /Remove:g Administrator "Authenticated Users" BUILTIN\Administrators BUILTIN Everyone System Users
## Optional Cleanup
Remove-Variable -Name Key
Remove-Variable -Name PERMS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment