# init-keys.ps1 # Lance ce script UNE FOIS avant le premier "docker compose up --build" # Il génère les deux paires de clés nécessaires au lab. $ErrorActionPreference = "Stop" $keysDir = Join-Path $PSScriptRoot "keys" if (-not (Test-Path $keysDir)) { New-Item -ItemType Directory -Path $keysDir | Out-Null } # ── Clé 1 : lab_rsa (Windows → gateway) ────────────────────────────────── $labKey = Join-Path $keysDir "lab_rsa" if (-not (Test-Path $labKey)) { Write-Host "Génération de la clé Windows → gateway (lab_rsa)..." ssh-keygen -t ed25519 -f $labKey -C "sshproxy-lab-client" Write-Host " OK : $labKey" } else { Write-Host " lab_rsa existe déjà, on garde." } # Copie aussi dans ~/.ssh pour pouvoir faire ssh sans -i $sshDir = Join-Path $env:USERPROFILE ".ssh" if (-not (Test-Path $sshDir)) { New-Item -ItemType Directory -Path $sshDir | Out-Null } Copy-Item $labKey (Join-Path $sshDir "lab_rsa") -Force Copy-Item "$labKey.pub" (Join-Path $sshDir "lab_rsa.pub") -Force Write-Host " Clé copiée dans $sshDir" # ── Clé 2 : gateway_rsa (gateway → dest1/dest2) ────────────────────────── $gwKey = Join-Path $keysDir "gateway_rsa" if (-not (Test-Path $gwKey)) { Write-Host "Génération de la clé gateway → dest (gateway_rsa)..." ssh-keygen -t ed25519 -f $gwKey -C "sshproxy-gateway-internal" Write-Host " OK : $gwKey" } else { Write-Host " gateway_rsa existe déjà, on garde." } Write-Host "" Write-Host "=== Clés prêtes. Lance maintenant : ===" Write-Host " docker compose up --build -d" Write-Host "" Write-Host "=== Pour te connecter : ===" Write-Host " ssh -i `"$((Join-Path $env:USERPROFILE '.ssh\lab_rsa'))`" -p 2222 testuser@localhost"