«

Windows Server 安装 OpenSSH Server

作者:myluzh 分类: Windows 长度:2390 阅读:583


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
  1. 启动sshd服务
    启动sshd服务
net start sshd

或者

Start-Service sshd

停止 sshd 服务

net stop sshd

或者

Stop-Service sshd

设置成自动

Set-Service -Name sshd -StartupType ‘Automatic’
  1. 开启防火墙
netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22
  1. 确认OpenSSH SSH Server自启动状态
    win+r cmd services.msc 查看ssh server是否为自启动

  2. 测试链接

$ ssh Administrator@192.168.1.101

Windows Server OpenSSH Server


正文到此结束
版权声明:若无特殊注明,本文皆为 Myluzh Blog 原创,转载请保留文章出处。
文章内容:https://itho.cn/win/195.html
文章标题:《Windows Server 安装 OpenSSH Server