Skip to content

Instantly share code, notes, and snippets.

@pdr-tuche
Created January 8, 2024 07:49
Show Gist options
  • Save pdr-tuche/b6a8beadd759efd6b70b09151e046795 to your computer and use it in GitHub Desktop.
Save pdr-tuche/b6a8beadd759efd6b70b09151e046795 to your computer and use it in GitHub Desktop.
Installing OpenSSH on Windows
# https://learn.microsoft.com/pt-br/windows-server/administration/openssh/openssh_install_firstuse?tabs=powershell
# pre-requisitos
# Um dispositivo que executa pelo menos o Windows Server 2019 ou Windows 10 (build 1809).
# PowerShell 5.1 ou posterior.
# Uma conta que é membro do grupo de administradores internos.
# saber se usuario e adm
(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator) True # saber se o Openssh ta instalado
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH'
#output
Name : OpenSSH.Client~~~~0.0.1.0
Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent
# adicionando o server que estava NotPresent
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
#vendo se instalou
Get-WindowsCapability -Online | Where-Object Name -like 'O
Name : OpenSSH.Client~~~~0.0.1.0
State : Installed
Name : OpenSSH.Server~~~~0.0.1.0
State : Installed
#iniciando servico
Start-Service sshd
# OPTIONAL but recommended:
Set-Service -Name sshd -StartupType 'Automatic'
# Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue | Select-Object Name, Enabled)) {
>> Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, creating it..."
>> New-NetFirewallRule -Name 'OpenSSH-Server-In-TCP' -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
>> } else {
>> Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists."
>> }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment