# Backup offline de la clé SSH Tloto (Windows). # N'affiche jamais le contenu de la clé privée. # Usage: # powershell -ExecutionPolicy Bypass -File deploy\vps-hardening\backup-ssh-key.ps1 # # ou avec chemin USB : # powershell -ExecutionPolicy Bypass -File deploy\vps-hardening\backup-ssh-key.ps1 -Dest E:\TlotoSSH-Backup param( [string]$Dest = "" ) $ErrorActionPreference = "Stop" $sshDir = Join-Path $env:USERPROFILE ".ssh" $priv = Join-Path $sshDir "id_ed25519" $pub = Join-Path $sshDir "id_ed25519.pub" if (-not (Test-Path $priv)) { throw "Private key not found: $priv" } if (-not (Test-Path $pub)) { throw "Public key not found: $pub" } Write-Host "" Write-Host "Fingerprint (public):" ssh-keygen -l -f $pub Write-Host "" if ([string]::IsNullOrWhiteSpace($Dest)) { Write-Host "Drives available:" Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Used -ne $null } | ForEach-Object { "{0}: {1} free {2:N1} GB" -f $_.Name, $_.Root, ($_.Free / 1GB) } Write-Host "" Write-Host "Branch un USB, puis indique la lettre (ex: E) ou un chemin complet." $Dest = Read-Host "Backup destination (ex: E:\TlotoSSH-Backup)" } if ($Dest.Length -eq 1) { $Dest = "${Dest}:\TlotoSSH-Backup" } elseif ($Dest -match '^[A-Za-z]:\\?$') { $Dest = Join-Path $Dest.TrimEnd('\') "TlotoSSH-Backup" } New-Item -ItemType Directory -Force -Path $Dest | Out-Null $stamp = Get-Date -Format "yyyyMMdd-HHmmss" $target = Join-Path $Dest "id_ed25519-backup-$stamp" New-Item -ItemType Directory -Force -Path $target | Out-Null Copy-Item -LiteralPath $priv -Destination (Join-Path $target "id_ed25519") -Force Copy-Item -LiteralPath $pub -Destination (Join-Path $target "id_ed25519.pub") -Force @" Tloto SSH key backup Created: $(Get-Date -Format o) PC user: $env:USERNAME Host fingerprint (pub): $(ssh-keygen -l -f $pub) RESTORE (new PC): 1. mkdir `$env:USERPROFILE\.ssh 2. Copy id_ed25519 + id_ed25519.pub into that folder 3. icacls `$env:USERPROFILE\.ssh\id_ed25519 /inheritance:r /grant:r "$env:USERNAME:(R)" 4. ssh deploy@YOUR_VPS_IP SECURITY: - Keep this USB offline / encrypted (BitLocker To Go recommended) - Never commit these files to git / cloud sync - After theft: revoke key on VPS (replace authorized_keys) via hoster console "@ | Set-Content -Encoding utf8 (Join-Path $target "README.txt") # Restrict NTFS ACL on private key copy when on NTFS try { $bakPriv = Join-Path $target "id_ed25519" icacls $bakPriv /inheritance:r | Out-Null icacls $bakPriv /grant:r "${env:USERNAME}:(R)" | Out-Null } catch { Write-Host "Note: could not tighten ACL on backup (non-NTFS USB?). Protect the media." } Write-Host "" Write-Host "OK — backup written to:" Write-Host " $target" Write-Host "Files: id_ed25519, id_ed25519.pub, README.txt" Write-Host "Store the USB in a safe place. Do not leave it plugged in daily."