# Copy Existing SSH Key to Proxmox # Ruleaza acest script pe PRIMARY ca Administrator # # Acest script copiaza cheia publica SSH existenta din profilul SYSTEM pe Proxmox param( [string]$ProxmoxHost = "10.0.20.202", [string]$ProxmoxUser = "root" ) Write-Host "=========================================" -ForegroundColor Cyan Write-Host "Copiere Cheie SSH Existenta -> 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" # Verifica daca cheia exista if (-not (Test-Path $PublicKeyPath)) { Write-Host "X Cheia publica nu exista: $PublicKeyPath" -ForegroundColor Red Write-Host " Scriptul trebuie rulat ca Administrator!" -ForegroundColor Yellow exit 1 } Write-Host "OK Cheie publica gasita: $PublicKeyPath" -ForegroundColor Green Write-Host "" Write-Host "-> Copiez cheia publica pe Proxmox ($ProxmoxHost)..." -ForegroundColor Yellow Write-Host " IMPORTANT: Vei fi intrebat de parola root pentru Proxmox!" -ForegroundColor Cyan Write-Host "" # Metoda simpla: folosim SCP pentru a copia fisierul temporar, apoi cat $tempFile = "C:\Windows\Temp\temp_pubkey.pub" Copy-Item $PublicKeyPath $tempFile -Force # Copiaza fisierul pe Proxmox & scp $tempFile "${ProxmoxUser}@${ProxmoxHost}:/tmp/temp_pubkey.pub" if ($LASTEXITCODE -ne 0) { Write-Host "X Eroare la copierea fisierului cu SCP" -ForegroundColor Red Remove-Item $tempFile -Force -ErrorAction SilentlyContinue exit 1 } # Adauga cheia in 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 "OK Cheie publica copiata pe Proxmox!" -ForegroundColor Green } else { Write-Host "X Eroare la adaugarea cheii in authorized_keys" -ForegroundColor Red exit 1 } Write-Host "" Write-Host "-> Testez conexiunea SSH fara parola..." -ForegroundColor Yellow # Testeaza 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 "OK Conexiune SSH functioneaza fara parola!" -ForegroundColor Green } else { Write-Host "X Conexiunea SSH nu functioneaza direct din acest cont" -ForegroundColor Yellow Write-Host " Dar cheia a fost adaugata - scheduled tasks (SYSTEM) ar trebui sa functioneze" -ForegroundColor Yellow } Write-Host "" Write-Host "=========================================" -ForegroundColor Green Write-Host "OK 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 aceasta cheie automat." -ForegroundColor Yellow Write-Host ""