Skip to content

Instantly share code, notes, and snippets.

@gravcat
Last active September 21, 2017 21:51
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 gravcat/106705c0cd818a1cc3288b4dd6e4c7d9 to your computer and use it in GitHub Desktop.
Save gravcat/106705c0cd818a1cc3288b4dd6e4c7d9 to your computer and use it in GitHub Desktop.
param (
[String]
$SSHPort = "22",
[String]
$version = "v0.0.20.0",
[String]
$packageName = "OpenSSH-Win64",
[String]
$githubReleaseUrl = "https://github.com/PowerShell/Win32-OpenSSH/releases/download/$version/$packageName.zip",
[String]
$dlDir = "C:\_maintainer",
[String]
$installDir = "C:\Program Files\" # will extract out as OpenSSH-Win64
)
Start-Transcript "C:\partial-sshd.txt"
try {
Write-Output "Switching to $installDir and installing sshd/ssh-agent services"
cd $installDir\$packageName
if (!(Test-Path $installDir\$packageName\install.complete)) {
.\install-sshd.ps1
New-Item -ItemType File "install-$version.complete"
}
}
catch {
Write-Error "Executing install-sshd.ps1 failed: $_"
}
try {
Write-Output "Generating host keys and ensuring proper permissions"
.\ssh-keygen.exe -A
.\FixHostFilePermissions.ps1 -Confirm:$false
}
catch {
Write-Error "Generating host keys failed: $_"
}
<#try {
Write-Output "Adding host keys to ssh-agent"
cd $installDir\$packageName
.\ssh-add.exe ssh_host_dsa_key -ErrorAction SilentlyContinue
.\ssh-add.exe ssh_host_rsa_key -ErrorAction SilentlyContinue
.\ssh-add.exe ssh_host_ecdsa_key -ErrorAction SilentlyContinue
.\ssh-add.exe ssh_host_ed25519_key -ErrorAction SilentlyContinue
Write-Output "Todo: Delete private keys as they are now loaded into ssh-agent"
}
catch {
Write-Error "Adding host keys to ssh-agent failed: $_"
}#>
try {
Write-Output "Creating firewall exception for $SSHPort/ssh"
New-NetFirewallRule -Protocol TCP -LocalPort $SSHPort -Direction Inbound -Action Allow -DisplayName SSH
}
catch {
Write-Error "Creating firewall exception for $SSHPort failed: $_"
}
try {
Write-Output "Setting SSH services to auto-start"
Set-Service sshd -StartupType Automatic
Set-Service ssh-agent -StartupType Automatic
}
catch {
Write-Error "Service manipulation, auto-start failed: $_"
}
try {
Write-Output "Starting sshd"
Restart-Service sshd
}
catch {
Write-Error "(re)Starting SSH service failed."
}
Stop-Transcript
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment