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

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"
12add-content -path "C:\programdata\ssh\sshd_config" -value "PasswordAuthentication no"
13New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Program Files\OpenSSH\sshd.exe"
14set-service sshd -StartupType automatic
15start-service sshd
16scoop install vim
17vim C:\ProgramData\ssh\administrators_authorized_keys
18$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
19$acl.SetAccessRuleProtection($true, $false)
20$administratorsRule = New-Object system.security.accesscontrol.filesystemaccessrule("Administrators","FullControl","Allow")
21$systemRule = New-Object system.security.accesscontrol.filesystemaccessrule("SYSTEM","FullControl","Allow")
22$acl.SetAccessRule($administratorsRule)
23$acl.SetAccessRule($systemRule)
24$acl | Set-Acl