28 lines
888 B
PowerShell
28 lines
888 B
PowerShell
$cfg = "C:\ProgramData\ssh\sshd_config"
|
|
Write-Host "=== Cambiando SSH a puerto 7022 ===" -ForegroundColor Green
|
|
Write-Host "Config: $cfg"
|
|
|
|
# Backup
|
|
Copy-Item $cfg "$cfg.bak" -Force -ErrorAction SilentlyContinue
|
|
|
|
# Leer, reemplazar, escribir
|
|
$content = Get-Content $cfg
|
|
$content = $content -replace '^\s*#?\s*Port\s+\d+', 'Port 7022'
|
|
$found = $content | Select-String '^Port 7022'
|
|
if (-not $found) { $content = @("Port 7022") + $content }
|
|
$content | Set-Content $cfg -Force
|
|
|
|
Write-Host "Verificacion:" -ForegroundColor Yellow
|
|
Get-Content $cfg | Select-String "Port"
|
|
|
|
Write-Host "`nReiniciando sshd..." -ForegroundColor Yellow
|
|
Stop-Service sshd -Force
|
|
Start-Sleep -Seconds 3
|
|
Start-Service sshd
|
|
|
|
Write-Host "`n=== netstat ===" -ForegroundColor Yellow
|
|
netstat -an | Select-String "LISTEN" | Select-String "7022"
|
|
|
|
Write-Host "`n=== LISTO ===" -ForegroundColor Green
|
|
Read-Host "Presione ENTER"
|