Skip to content

Instantly share code, notes, and snippets.

@janoskk
Last active November 2, 2021 09:45
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 janoskk/735a27257c44a76880c2d578109b4213 to your computer and use it in GitHub Desktop.
Save janoskk/735a27257c44a76880c2d578109b4213 to your computer and use it in GitHub Desktop.
Authorized keys on Windows 10 server

TL;DR of a very useful readme from https://gist.github.com/asheroto/80d5f85e90d92e7f8e40e9d1a3dea7ad:

On the client

export USER_AT_HOST="host-to-ssh"
export PUBKEYPATH="$HOME/.ssh/id_rsa.pub"
ssh $USER_AT_HOST  "powershell New-Item -Force -ItemType Directory -Path \"\$HOME\\.ssh\"; Add-Content -Force -Path \"\\programdata\\ssh\\administrators_authorized_keys\" -Value '$(tr -d '\n\r' < "$PUBKEYPATH")'"

On the server

$ak = "$ENV:ProgramData\ssh\administrators_authorized_keys"
$acl = Get-Acl $ak
$acl.SetAccessRuleProtection($true, $false)
$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
$acl.SetAccessRule($administratorsRule)
$acl.SetAccessRule($systemRule)
$acl | Set-Acl

Check the results:

Get-Acl "$ENV:ProgramData\ssh\administrators_authorized_keys" | Format-List
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment