<# .SYNOPSIS AgentSesh All-in-One Host Setup for Windows 10 / 11 .DESCRIPTION Run in PowerShell / Windows Terminal AS ADMINISTRATOR (UAC prompt required): 1. OpenSSH Server (SSH + SFTP subsystem on TCP port 22 + Firewall rule + PowerShell default shell) 2. Native psmux (tmux-compatible ConPTY multiplexer — no WSL required, working Ctrl-C) 3. TightVNC Server on TCP port 5900 (replaces Windows RDP-only default for VNC Screen Sharing) 4. Disables AC sleep so long agent sessions stay online 5. Checks Tailscale & prints exact Administrator SSH key enrollment path #> $ErrorActionPreference = 'Stop' # Check Administrator elevation (UAC) $isAdmin = ([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) if (-not $isAdmin) { Write-Host "`n[!] Administrator privileges required." -ForegroundColor Yellow Write-Host " Right-click Windows Terminal or PowerShell -> 'Run as Administrator', click Yes on UAC, then re-run this script.`n" -ForegroundColor Yellow exit 1 } Write-Host "`n==> AgentSesh All-in-One Host Setup for Windows`n" -ForegroundColor Cyan # 1. OpenSSH Server (SSH + SFTP) Write-Host "[1/6] Installing & configuring Windows OpenSSH Server (SSH + SFTP)..." $sshCap = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*' if ($sshCap.State -ne 'Installed') { Add-WindowsCapability -Online -Name $sshCap.Name | Out-Null } Set-Service -Name sshd -StartupType Automatic Start-Service sshd # Ensure SFTP subsystem is enabled in sshd_config $sshdConfig = "$env:ProgramData\ssh\sshd_config" if (Test-Path $sshdConfig) { $cfg = Get-Content $sshdConfig -Raw if ($cfg -notmatch '(?m)^\s*Subsystem\s+sftp') { Add-Content -Path $sshdConfig -Value "`nSubsystem sftp sftp-server.exe" Restart-Service sshd } } # Set PowerShell as default OpenSSH shell so AgentSesh commands run cleanly New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force | Out-Null if (-not (Get-NetFirewallRule -Name "AgentSesh-SSH" -ErrorAction SilentlyContinue)) { New-NetFirewallRule -Name "AgentSesh-SSH" -DisplayName "AgentSesh OpenSSH Server (TCP 22)" ` -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null } Write-Host " OpenSSH Server & SFTP active on TCP port 22." -ForegroundColor Green # 2. Native psmux (tmux-compatible ConPTY multiplexer for Windows) Write-Host "[2/6] Installing psmux (native Windows terminal multiplexer, no WSL)..." $psmuxDir = "C:\ProgramData\psmux\bin" $psmuxExe = Join-Path $psmuxDir "psmux.exe" $existingMux = Get-Command psmux.exe -ErrorAction SilentlyContinue if (-not $existingMux -and -not (Test-Path $psmuxExe)) { if (Get-Command winget -ErrorAction SilentlyContinue) { winget install --id marlocarlo.psmux --accept-source-agreements --accept-package-agreements -e 2>$null } $existingMux = Get-Command psmux.exe -ErrorAction SilentlyContinue if (-not $existingMux) { if (Get-Command cargo -ErrorAction SilentlyContinue) { cargo install psmux } else { Write-Host " Tip: Install psmux via 'winget install marlocarlo.psmux' or 'cargo install psmux' and add to System PATH." -ForegroundColor Yellow } } } else { Write-Host " psmux already installed." -ForegroundColor Green } # 3. TightVNC Server (Standard VNC on TCP 5900 — replaces Windows RDP-only default) Write-Host "[3/6] Installing TightVNC Server (TCP 5900 — VNC Screen Sharing)..." $tvncRunning = Get-Service -Name "tvnserver" -ErrorAction SilentlyContinue if (-not $tvncRunning) { if (Get-Command winget -ErrorAction SilentlyContinue) { winget install --id GlavSoft.TightVNC --accept-source-agreements --accept-package-agreements --silent -e } else { Write-Host " Download TightVNC Server from https://www.tightvnc.com/download.php and install the Server component." -ForegroundColor Yellow } } else { Write-Host " TightVNC Server service already installed." -ForegroundColor Green } if (-not (Get-NetFirewallRule -Name "AgentSesh-VNC" -ErrorAction SilentlyContinue)) { New-NetFirewallRule -Name "AgentSesh-VNC" -DisplayName "AgentSesh VNC Screen Sharing (TCP 5900)" ` -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 5900 -Profile Private | Out-Null } # 4. Prevent AC Sleep so coding agents never suspend mid-task Write-Host "[4/6] Disabling AC power sleep..." powercfg /change standby-timeout-ac 0 2>$null # 5. Tailscale check Write-Host "[5/6] Checking Tailscale..." $tsIP = "(not installed - run: winget install Tailscale.Tailscale)" if (Get-Command tailscale -ErrorAction SilentlyContinue) { $val = (& tailscale ip -4 2>$null | Select-Object -First 1) if ($val) { $tsIP = $val } else { $tsIP = "(installed - sign in via Tailscale tray icon)" } } # 6. Summary & manual security checklist Write-Host "[6/6] Gathering Windows host info..." $lanIP = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object { $_.IPAddress -notlike '127.*' -and $_.IPAddress -notlike '169.254.*' -and $_.IPAddress -notlike '100.*' } | Select-Object -First 1).IPAddress $hostLocal = "$($env:COMPUTERNAME.ToLower()).local" $user = $env:USERNAME Write-Host @" ==================================================================== AgentSesh Windows Host Setup Complete! ==================================================================== System: Windows Username: $user LAN Address: $hostLocal (or $lanIP) Tailscale IP: $tsIP SSH / SFTP: ON (port 22) Multiplexer: psmux (native ConPTY, no WSL) VNC Desktop: TightVNC Server (port 5900) Required Manual Steps (one-time): 1. Set VNC Password: Open Start -> TightVNC Service Configuration -> Server tab -> Set Primary Password (used by AgentSesh Screen). 2. SSH Key for Admin Accounts: Copy your AgentSesh public key into C:\ProgramData\ssh\administrators_authorized_keys (NOT ~/.ssh) and lock ACLs: icacls.exe "C:\ProgramData\ssh\administrators_authorized_keys" /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F" 3. In AgentSesh -> Add Host: choose System = Windows! ==================================================================== "@ -ForegroundColor Cyan