Created
March 2, 2026 13:33
-
-
Save ciekawy/ca14c92f56a56ca8492a3bb48f5423df to your computer and use it in GitHub Desktop.
WEB-9: Windows Server 2022 automated setup script (SSH + .NET SDK + Git)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Windows Server 2022 Setup Script - WEB-9 | |
| # Quick setup for SSH + .NET SDK + Git | |
| # Run in Administrator PowerShell | |
| Set-ExecutionPolicy Bypass -Scope Process -Force | |
| [System.Net.ServicePointManager]::SecurityProtocol = 3072 | |
| Write-Host "Installing Chocolatey..." -ForegroundColor Cyan | |
| iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) | |
| $env:PATH = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User") | |
| Write-Host "Installing packages (this takes ~10 minutes)..." -ForegroundColor Cyan | |
| choco install -y openssh powershell-core dotnet-8.0-sdk git | |
| Write-Host "Configuring SSH..." -ForegroundColor Cyan | |
| Start-Service sshd | |
| Set-Service -Name sshd -StartupType Automatic | |
| New-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -DisplayName "OpenSSH Server (sshd)" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -ErrorAction SilentlyContinue | |
| Add-Content -Path C:\ProgramData\ssh\sshd_config -Value "`nSubsystem powershell C:/Progra~1/PowerShell/7/pwsh.exe -sshs -NoLogo" | |
| Restart-Service sshd | |
| Write-Host "Creating test project..." -ForegroundColor Cyan | |
| New-Item -ItemType Directory -Path C:\Projects -Force | Out-Null | |
| cd C:\Projects | |
| dotnet new console -n HelloWindows | |
| cd HelloWindows | |
| dotnet build | |
| Write-Host "Adding SSH key..." -ForegroundColor Cyan | |
| $authorizedKeysFile = "C:\ProgramData\ssh\administrators_authorized_keys" | |
| $key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIO9VR+9HrxMs+2NxN2h8Td6rCDP8eupti1BtqFK1pSdX coder@myfirst" | |
| New-Item -Path $authorizedKeysFile -ItemType File -Force -Value $key | Out-Null | |
| icacls.exe $authorizedKeysFile /inheritance:r | Out-Null | |
| icacls.exe $authorizedKeysFile /grant "SYSTEM:(F)" | Out-Null | |
| icacls.exe $authorizedKeysFile /grant "BUILTIN\Administrators:(F)" | Out-Null | |
| Restart-Service sshd | |
| Write-Host "" | |
| Write-Host "✅ Setup complete! SSH key added." -ForegroundColor Green | |
| Write-Host "You can now connect via: ssh Administrator@46.224.201.14" -ForegroundColor Cyan |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment