Skip to content

Instantly share code, notes, and snippets.

@Jamp
Created April 29, 2026 22:43
Show Gist options
  • Select an option

  • Save Jamp/b878551f60cabd896c12df5c4cdaca8f to your computer and use it in GitHub Desktop.

Select an option

Save Jamp/b878551f60cabd896c12df5c4cdaca8f to your computer and use it in GitHub Desktop.
FishControl - Configurar SSH en Windows
param()
$usuario = "Cristhian"
$clavePublica = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEo/Yt3YxSroNMhXuLqRE8YS5q1vkz6x9h6kVwfaUjl5 jaro@tooldata.io"
Write-Host ">> Verificando OpenSSH Server..." -ForegroundColor Yellow
$sshFeature = Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH.Server*'
if ($sshFeature.State -ne 'Installed') {
Write-Host " Instalando OpenSSH Server..." -ForegroundColor Yellow
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
} else {
Write-Host " OpenSSH Server ya instalado." -ForegroundColor Green
}
Start-Service sshd
Set-Service -Name sshd -StartupType Automatic
Write-Host " Servicio sshd iniciado y automatico." -ForegroundColor Green
Write-Host ">> Configurando firewall puerto 22..." -ForegroundColor Yellow
$regla = Get-NetFirewallRule -Name "sshd" -ErrorAction SilentlyContinue
if (-not $regla) {
New-NetFirewallRule -Name sshd -DisplayName "OpenSSH Server (sshd)" -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22 | Out-Null
Write-Host " Regla de firewall creada." -ForegroundColor Green
} else {
Write-Host " Regla de firewall ya existe." -ForegroundColor Green
}
Write-Host ">> Configurando clave SSH del usuario $usuario..." -ForegroundColor Yellow
$sshDir = "C:\Users\$usuario\.ssh"
New-Item -ItemType Directory -Force -Path $sshDir | Out-Null
$authFile = "$sshDir\authorized_keys"
Set-Content -Path $authFile -Value $clavePublica -Encoding UTF8
icacls $authFile /inheritance:r | Out-Null
icacls $authFile /grant "${usuario}:(F)" | Out-Null
icacls $authFile /grant "SYSTEM:(F)" | Out-Null
Write-Host " Clave configurada en $authFile" -ForegroundColor Green
Write-Host ">> Configurando clave para administradores..." -ForegroundColor Yellow
$adminAuthFile = "C:\ProgramData\ssh\administrators_authorized_keys"
Set-Content -Path $adminAuthFile -Value $clavePublica -Encoding UTF8
icacls $adminAuthFile /inheritance:r | Out-Null
icacls $adminAuthFile /grant "SYSTEM:(F)" | Out-Null
icacls $adminAuthFile /grant "BUILTIN\Administrators:(F)" | Out-Null
Write-Host " Archivo de administradores configurado." -ForegroundColor Green
Write-Host ">> Reiniciando servicio SSH..." -ForegroundColor Yellow
Restart-Service sshd
Write-Host " Servicio reiniciado." -ForegroundColor Green
Write-Host ""
Write-Host "Configuracion completada. IP de este equipo:" -ForegroundColor Green
Get-NetIPAddress -AddressFamily IPv4 | Where-Object {
$_.IPAddress -notlike "127.*" -and $_.IPAddress -notlike "169.*"
} | ForEach-Object {
Write-Host " $($_.IPAddress)" -ForegroundColor White
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment