Files
runtipi/apps/rego-tunnel/vpn_scripts-not-used/03_setup-ssh-keys.ps1
alexz 0461ffec7c
Some checks failed
Test / test (push) Has been cancelled
.
2025-12-28 13:10:05 +00:00

35 lines
1.4 KiB
PowerShell

# Setup SSH Keys
# Run as Administrator in PowerShell
$Username = if ($env:REGO_USER) { $env:REGO_USER } else { $env:USERNAME }
$PublicKey = if ($env:REGO_SSH_PUBKEY) { $env:REGO_SSH_PUBKEY } else { "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGHUQnw0WfeFRQx76UlImXXhu3xeOH41PmDRid8pWK1D default-key" }
Write-Host "=== Setting up SSH Keys ===" -ForegroundColor Cyan
Write-Host "Using username: $Username" -ForegroundColor Yellow
# User authorized_keys
$userSshDir = "C:\Users\$Username\.ssh"
$userAuthKeys = "$userSshDir\authorized_keys"
Write-Host "Creating user .ssh directory..." -ForegroundColor Yellow
New-Item -ItemType Directory -Path $userSshDir -Force | Out-Null
Write-Host "Adding key to user authorized_keys..." -ForegroundColor Yellow
Add-Content -Path $userAuthKeys -Value $PublicKey -Force
# Fix permissions for user file
icacls $userAuthKeys /inheritance:r /grant "${Username}:F" /grant "SYSTEM:F"
# Administrator authorized_keys (for admin users)
$adminAuthKeys = "C:\ProgramData\ssh\administrators_authorized_keys"
Write-Host "Adding key to administrators_authorized_keys..." -ForegroundColor Yellow
Add-Content -Path $adminAuthKeys -Value $PublicKey -Force
# Fix permissions for admin file (required by OpenSSH)
icacls $adminAuthKeys /inheritance:r /grant "Administrators:F" /grant "SYSTEM:F"
Write-Host ""
Write-Host "SSH keys configured!" -ForegroundColor Green
Write-Host "You can now SSH in with the configured key." -ForegroundColor Yellow