Files
dtic-DIIAA/scripts/w-zombi/install_ssh.ps1
T

31 lines
1.8 KiB
PowerShell

Write-Host "==========================================================" -ForegroundColor Cyan
Write-Host "INSTALANDO Y HABILITANDO OPENSSH SERVER NATIVO EN DC01" -ForegroundColor Cyan
Write-Host "==========================================================" -ForegroundColor Cyan
try {
$sshCheck = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
if ($sshCheck.State -ne 'Installed') {
Write-Host "Instalando caracteristica OpenSSH.Server (esto puede tomar un minuto)..." -ForegroundColor Yellow
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0 | Out-Null
} else {
Write-Host "OpenSSH.Server ya se encuentra instalado." -ForegroundColor Green
}
Write-Host "Configurando servicio sshd en Inicio Automatico..." -ForegroundColor Yellow
Set-Service -Name sshd -StartupType 'Automatic'
Start-Service sshd -ErrorAction SilentlyContinue
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Host "Abriendo puerto TCP 22 en el Firewall local..." -ForegroundColor Yellow
New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null
}
$ip = (Get-NetIPAddress -AddressFamily IPv4 | Where-Object InterfaceAlias -notmatch 'Loopback').IPAddress
Write-Host "OpenSSH Server instalado y corriendo exitosamente en el puerto 22." -ForegroundColor Green
Write-Host "La IA ya puede conectarse a este nodo mediante: ssh Administrator@$($ip[0])" -ForegroundColor Green
} catch {
Write-Host "Fallo al instalar SSH: $_" -ForegroundColor Red
}
Write-Host "==========================================================" -ForegroundColor Cyan