From 204525ebb740756fc4f403cbb10e5fe74dc71d98 Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 8 Nov 2023 23:11:45 -0700 Subject: [PATCH] WIP: sshd --- sshd/README.md | 0 sshd/install.ps1 | 62 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 sshd/README.md create mode 100644 sshd/install.ps1 diff --git a/sshd/README.md b/sshd/README.md new file mode 100644 index 000000000..e69de29bb diff --git a/sshd/install.ps1 b/sshd/install.ps1 new file mode 100644 index 000000000..d2ceeadc6 --- /dev/null +++ b/sshd/install.ps1 @@ -0,0 +1,62 @@ +#!/usr/bin/env pwsh + +$Esc = [char]27 +$Warn = "${Esc}[1m[33m" +$ResetAll = "${Esc}[0m" + +# See +# - +# - +# - + +function InstallOpenSSHServer { + $OpenSSHServer = Get-WindowsCapability -Online | ` + Where-Object -Property Name -Like "OpenSSH.Server*" + IF (-Not ($OpenSSHServer.State -eq "Installed")) { + Add-WindowsCapability -Online -Name $sshd.Name + } + + $Sshd = Get-Service -Name "sshd" + IF (-Not ($Sshd.Status -eq "Running")) { + Start-Service "sshd" + } + IF (-Not ($Sshd.StartupType -eq "Automatic")) { + Set-Service -Name "sshd" -StartupType "Automatic" + } + + $SshAgent = Get-Service -Name "ssh-agent" + IF (-Not ($SshAgent.Status -eq "Running")) { + Start-Service "ssh-agent" + } + IF (-Not ($SshAgent.StartupType -eq "Automatic")) { + Set-Service -Name "ssh-agent" -StartupType "Automatic" + } + + Install-Module -Force OpenSSHUtils -Scope AllUsers +} + +function SelfElevate { + Write-Host "${Warn}Installing 'sshd' requires Admin privileges${ResetAll}" + Write-Host "Install will continue automatically in 5 seconds..." + Sleep 5.0 + + # Self-elevate the script if required + $CurUser = New-Object Security.Principal.WindowsPrincipal( + [Security.Principal.WindowsIdentity]::GetCurrent() + ) + $IsAdmin = $CurUser.IsInRole( + [Security.Principal.WindowsBuiltInRole]::Administrator + ) + if ($IsAdmin) { + Return 0 + } + + $CurLoc = Get-Location + $CommandLine = "-File `"" + $MyInvocation.MyCommand.Path + "`" " + $MyInvocation.UnboundArguments + Start-Process -FilePath PowerShell.exe -Verb Runas -ArgumentList $CommandLine + Set-Location $CurLoc + Exit 0 +} + +SelfElevate +InstallOpenSSHServer