Windows 安装 OpenSSH
官方介绍地址:
https://learn.microsoft.com/zh-cn/windows-server/administration/openssh/openssh_install_firstuse
安装方式
1.使用设置 -> 应用进行安装
2.使用PowerShell 安装 OpenSSH
1.查看安装情况
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
2.根据需要安装服务器或客户端组件
# 安装 OpenSSH 客户端
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# 安装 OpenSSH 服务端
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0
启用
若要启动并配置 OpenSSH 服务器来开启使用,请以管理员身份打开 PowerShell,然后运行以下命令来启动 sshd service
# 开启sshd service
Start-Service sshd
# 配置服务类型
Set-Service -Name sshd -StartupType 'Automatic'
# 确认防火墙规则已配置。它应该由安装程序自动创建。运行以下程序进行验证
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."
}
连接
1.在服务端创建客户端连接时使用的账号
1.使用powershell创建
net user username password /add
2.使用用户账号管理程序创建[推荐]
运行或搜索,输入"netplwiz"并回车
3.使用SSH客户端进行连接
在Windows 10 或 Windows Server 2019使用OpenSSH 客户端连接到 OpenSSH 服务器。
请务必在客户端以管理员身份运行 PowerShell
ssh username@hostip
卸载【如果服务在运行,可能需要主机重启】
1.使用Windows 设置来卸载 OpenSSH[略]
2.使用 PowerShell 卸载 OpenSSH
# 卸载 OpenSSH 客户端
Remove-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0
# 卸载 OpenSSH 服务端
Remove-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0