Skip to content

Instantly share code, notes, and snippets.

@alyssadev
Last active March 13, 2021 14:17
Show Gist options
  • Save alyssadev/a1049c254c8d1a6924a9b823d2188444 to your computer and use it in GitHub Desktop.
Save alyssadev/a1049c254c8d1a6924a9b823d2188444 to your computer and use it in GitHub Desktop.
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
Set-ExecutionPolicy RemoteSigned
New-Item -path $profile -type file -force
Add-Content -path $profile -value '[Net.ServicePointManager]::SecurityProtocol = "tls12, tls11, tls"'
& $profile
iwr -useb get.scoop.sh | iex
scoop install git
scoop update
iwr https://github.com/PowerShell/Win32-OpenSSH/releases/download/v8.1.0.0p1-Beta/OpenSSH-Win64.zip -outfile "C:\Program Files\OpenSSH-Win64.zip"
expand-archive -path "C:\Program Files\OpenSSH-Win64.zip" -destinationpath "C:\Program Files"
move-item "C:\Program Files\OpenSSH-Win64" "C:\Program Files\OpenSSH"
powershell.exe -ExecutionPolicy Bypass -File "C:\Program Files\OpenSSH\install-sshd.ps1"
add-content -path "C:\programdata\ssh\sshd_config" -value "PasswordAuthentication no"
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH SSH Server' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -Program "C:\Program Files\OpenSSH\sshd.exe"
set-service sshd -StartupType automatic
start-service sshd
scoop install vim
vim C:\ProgramData\ssh\administrators_authorized_keys
$acl = Get-Acl C:\ProgramData\ssh\administrators_authorized_keys
$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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment