# Copy Existing SSH Key to Proxmox # Rulează acest script pe PRIMARY ca Administrator # # Acest script copiază cheia publică SSH existentă din profilul SYSTEM pe Proxmox param( [string]$ProxmoxHost = "10.0.20.202", [string]$ProxmoxUser = "root" ) Write-Host "=========================================" -ForegroundColor Cyan Write-Host "Copiere Cheie SSH Existentă → Proxmox DR" -ForegroundColor Cyan Write-Host "=========================================" -ForegroundColor Cyan Write-Host "" $SystemSSHDir = "C:\Windows\System32\config\systemprofile\.ssh" $PublicKeyPath = "$SystemSSHDir\id_rsa.pub" $PrivateKeyPath = "$SystemSSHDir\id_rsa" # Verifică dacă cheia există if (-not (Test-Path $PublicKeyPath)) { Write-Host "✗ Cheia publică nu există: $PublicKeyPath" -ForegroundColor Red Write-Host " Scriptul trebuie rulat ca Administrator!" -ForegroundColor Yellow exit 1 } Write-Host "✓ Cheie publică găsită: $PublicKeyPath" -ForegroundColor Green Write-Host "" Write-Host "→ Copiez cheia publică pe Proxmox ($ProxmoxHost)..." -ForegroundColor Yellow Write-Host " IMPORTANT: Vei fi întrebat de parola root pentru Proxmox!" -ForegroundColor Cyan Write-Host "" # Metodă simplă: folosim SCP pentru a copia fișierul temporar, apoi cat $tempFile = "C:\Windows\Temp\temp_pubkey.pub" Copy-Item $PublicKeyPath $tempFile -Force # Copiază fișierul pe Proxmox & scp $tempFile "${ProxmoxUser}@${ProxmoxHost}:/tmp/temp_pubkey.pub" if ($LASTEXITCODE -ne 0) { Write-Host "✗ Eroare la copierea fișierului cu SCP" -ForegroundColor Red Remove-Item $tempFile -Force -ErrorAction SilentlyContinue exit 1 } # Adaugă cheia în authorized_keys & ssh "${ProxmoxUser}@${ProxmoxHost}" "mkdir -p /root/.ssh; chmod 700 /root/.ssh; cat /tmp/temp_pubkey.pub >> /root/.ssh/authorized_keys; chmod 600 /root/.ssh/authorized_keys; rm /tmp/temp_pubkey.pub; echo 'SSH key added'" Remove-Item $tempFile -Force -ErrorAction SilentlyContinue if ($LASTEXITCODE -eq 0) { Write-Host "✓ Cheie publică copiată pe Proxmox!" -ForegroundColor Green } else { Write-Host "✗ Eroare la adăugarea cheii în authorized_keys" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "→ Testez conexiunea SSH fără parolă..." -ForegroundColor Yellow # Testează conexiunea (cu cheia din profilul SYSTEM) $testResult = & ssh -o StrictHostKeyChecking=no -i $PrivateKeyPath "${ProxmoxUser}@${ProxmoxHost}" "echo 'SSH connection OK'" 2>&1 if ($LASTEXITCODE -eq 0) { Write-Host "✓ Conexiune SSH funcționează fără parolă!" -ForegroundColor Green } else { Write-Host "✗ Conexiunea SSH nu funcționează direct din acest cont" -ForegroundColor Yellow Write-Host " Dar cheia a fost adăugată - scheduled tasks (SYSTEM) ar trebui să funcționeze" -ForegroundColor Yellow } Write-Host "" Write-Host "=========================================" -ForegroundColor Green Write-Host "✓ Setup complet!" -ForegroundColor Green Write-Host "=========================================" -ForegroundColor Green Write-Host "" Write-Host "Cheia din profilul SYSTEM: $PrivateKeyPath" -ForegroundColor Cyan Write-Host "Scheduled tasks vor folosi această cheie automat." -ForegroundColor Yellow Write-Host ""