Last active 1615609058

A script that should configure a given windows machine to have openssh running at least. opens vim to paste in authorized keys, installs scoop as well

Revision b9105cfc177ba84ea652c15ba6d8e23ead8e0486

win-remote-ssh.ps1 Raw
1Set-ExecutionPolicy RemoteSigned
2New-Item -path $profile -type file -force
3Add-Content -path $profile -value '[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"'
4& $profile
5iwr -useb get.scoop.sh | iex
6scoop install git
7scoop update
8iwr https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-Win64.zip -outfile "C:\Program Files\OpenSSH-Win64.zip"
9expand-archive -path "C:\Program Files\OpenSSH-Win64.zip" -destinationpath "C:\Program Files"
10move-item "C:\Program Files\OpenSSH-Win64" "C:\Program Files\OpenSSH"
11powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\OpenSSH\install-sshd.ps1"
12New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Program Files\OpenSSH\sshd.exe"
13set-service sshd -StartupType automatic
14start-service sshd
15scoop install vim
16vim C:\ProgramData\ssh\administrators_authorized_keys
17$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
18$acl.SetAccessRuleProtection($true, $false)
19$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
20$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
21$acl.SetAccessRule($administratorsRule)
22$acl.SetAccessRule($systemRule)
23$acl | Set-Acl