Lime logo洛明Lime
← 返回卡片墙幼苗速查表

Windows 安装 ssh server/client

Get started with OpenSSH Server for Windows

Install

Terminal window
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
Terminal window
# 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
Terminal window
# 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. Run the following to verify
if (!(Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
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."
}

Uninstall

Terminal window
# 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
Terminal window
if ((Get-NetFirewallRule -Name "OpenSSH-Server-In-TCP" -ErrorAction SilentlyContinue)) {
Write-Output "Firewall rule 'OpenSSH-Server-In-TCP' is being removed."
Remove-NetFirewallRule -Name 'OpenSSH-Server-In-TCP'
} else {
Write-Output "Firewall Rule 'OpenSSH-Server-In-TCP' does not exist, removal failed..."
}

生成新的 SSH 密钥并将其添加到 ssh-agent - GitHub 文档