Myluzh Blog

Windows Server 安装 OpenSSH Server

发布时间: 2022-9-15 文章作者: myluzh 分类名称: Windows 朗读文章


0x01 PowerShell自动安装
1、安装软件
# Install the OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install the OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

2、启动软件
# Start the sshd service
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.
Get-NetFirewallRule -Name *ssh*

# There should be a firewall rule named "OpenSSH-Server-In-TCP", which should be enabled
# If the firewall does not exist, create one
New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22

3、卸载软件
# Uninstall the OpenSSH Client
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Uninstall the OpenSSH Server
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


0x02 手动安装OpenSSH Server


1.github仓库https://github.com/PowerShell/Win32-OpenSSH/releases下载OpenSSH-Win64.zip
并且解压到C:\Program Files,其中 install-sshd.ps1 是安装文件

2.安装sshd服务
打开powershell,执行以下命令进行安装
powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1

3.启动sshd服务
启动sshd服务
net start sshd
或者
Start-Service sshd
停止 sshd 服务
net stop sshd
或者
Stop-Service sshd
设置成自动
Set-Service -Name sshd -StartupType ‘Automatic’

4.开启防火墙
 netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22

5.确认OpenSSH SSH Server自启动状态
win+r cmd services.msc 查看ssh server是否为自启动

6.测试链接
$ ssh Administrator@192.168.1.101 




标签: Windows Server OpenSSH Server

发表评论