How to set up the SSH keys on Windows

https://superuser.com/questions/1296024/windows-ssh-permissions-for-private-key-are-too-open

TL;DR

New-Variable -Name Key -Value "$env:UserProfile\.ssh\id_rsa"
Icacls $Key /c /t /Inheritance:d
Icacls $Key /c /t /Grant ${env:UserName}:F
TakeOwn /F $Key
Icacls $Key /c /t /Grant:r ${env:UserName}:F
Icacls $Key /c /t /Remove:g Administrator "Authenticated Users" BUILTIN\Administrators BUILTIN Everyone System Users
Icacls $Key
Remove-Variable -Name Key

PowerShell:

  • Set Key File Variable:
    New-Variable -Name Key -Value “$env:UserProfile.ssh\id_rsa”

  • Remove Inheritance:
    Icacls $Key /c /t /Inheritance:d

  • Set Ownership to Owner:

    • Key’s within $env:UserProfile:

      Icacls $Key /c /t /Grant ${env:UserName}:F

    • Key’s outside of $env:UserProfile:

      TakeOwn /F $Key
      Icacls $Key /c /t /Grant:r ${env:UserName}:F

  • Remove All Users, except for Owner:
    Icacls $Key /c /t /Remove:g Administrator “Authenticated Users” BUILTIN\Administrators BUILTIN Everyone System Users

Verify:

Icacls $Key

Remove Variable:

Remove-Variable -Name Key

Leave a Reply

Your email address will not be published. Required fields are marked *