| 190 | /** PowerShell user-data: enable OpenSSH, default the shell to PowerShell, and |
| 191 | * authorize our public key for the Administrator account. */ |
| 192 | const windowsUserData = (publicKey: string): string => |
| 193 | [ |
| 194 | "<powershell>", |
| 195 | "Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0", |
| 196 | "Set-Service -Name sshd -StartupType Automatic", |
| 197 | "Start-Service sshd", |
| 198 | "New-ItemProperty -Path 'HKLM:\\SOFTWARE\\OpenSSH' -Name DefaultShell -Value 'C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe' -PropertyType String -Force", |
| 199 | "New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 -ErrorAction SilentlyContinue", |
| 200 | "$akf = 'C:\\ProgramData\\ssh\\administrators_authorized_keys'", |
| 201 | `Set-Content -Path $akf -Value '${publicKey}'`, |
| 202 | "icacls $akf /inheritance:r /grant 'Administrators:F' /grant 'SYSTEM:F'", |
| 203 | "</powershell>", |
| 204 | ].join("\n"); |
| 205 | |
| 206 | const linuxUserData = (publicKey: string): string => |
| 207 | ["#cloud-config", "ssh_authorized_keys:", ` - ${publicKey}`].join("\n"); |