OpenSSH 是可使用 SSH 通訊協定的遠端登入的連線工具。 它對用戶端和伺服器之間的所有流量進行加密,以消除竊聽、連線劫持和其他攻擊。
OpenSSH 相容的用戶端可用來連線到 Windows Server 和 Windows 用戶端裝置。
Important
If you downloaded the OpenSSH beta from the GitHub repo at PowerShell/Win32-OpenSSH, follow the instructions listed there, not the ones in this article. 部分 Win32-OpenSSH 存放庫中的資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對該處提供的資訊,不做任何明確或隱含的瑕疵擔保。
Prerequisites
開始前,您的電腦硬體必須符合下列需求:
至少執行 Windows Server 2019 或 Windows 10 (組建 1809) 的裝置。
PowerShell 5.1 或更新版本。
屬於內建 Administrators 群組成員的帳戶。
Prerequisites check
若要驗證您的環境,請開啟提升權限的 PowerShell 工作階段,然後執行下列動作:
Enter winver.exe and press enter to see the version details for your Windows device.
執行
$PSVersionTable.PSVersion
。 確認您的主要版本至少為 5,次要版本至少為 1。 深入了解如何 在 Windows 上安裝 PowerShell。執行下列命令。 輸出會顯示
True
您是內建 Administrator 群組的成員。(New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)
啟用 Windows Server 2025 的 OpenSSH
從 Windows Server 2025 開始,預設會安裝 OpenSSH。 您也可以在 伺服器管理員 中啟用或停用sshd
服務。
若要使用 伺服器管理員 啟用 SSHD:
In Server Manager, on the navigation pane to the left, select Local Server.
In the Properties window, locate Remote SSH Access.
Select Disabled to enable the OpenSSH service.
Note
If you need to allow or restrict specific users or groups from using OpenSSH for remote access, add them to the OpenSSH Users user group.
安裝適用於 Windows Server 的 OpenSSH
在 Windows 10 裝置上安裝 OpenSSH 元件:
Open Settings, select System, then select Optional Features.
掃描清單,查看是否已安裝 OpenSSH。 如果沒有,請在頁面頂端選取 [新增功能],然後:
Find OpenSSH Client, then select Install
Find OpenSSH Server, then select Install
Open the Services desktop app. (Select Start, type services.msc in the search box, and then select the Service app or press ENTER.)
在詳細資料窗格中,按兩下 OpenSSH SSH Server。
On the General tab, from the Startup type drop-down menu, select Automatic and then select Ok.
To start the service, select Start.
在 Windows 11 裝置上安裝 OpenSSH 元件:
Open Settings, select System, then select Optional Features.
掃描清單,查看是否已安裝 OpenSSH。 If not, at the top of the page, select View Features, then:
Search for OpenSSH Client, select Next, then select Install
Search for OpenSSH Server, select Next, then select Install
Open the Services desktop app. (Select Start, type services.msc in the search box, and then select the Service app or press ENTER.)
在詳細資料窗格中,按兩下 OpenSSH SSH Server。
On the General tab, from the Startup type drop-down menu, select Automatic and then select Ok.
To start the service, select Start.
在 Windows Server 裝置上安裝 OpenSSH 元件:
Open Settings, select System, then select Optional Features (also referred to as Manage optional features).
掃描清單,查看是否已安裝 OpenSSH。 如果沒有,請在頁面頂端選取 [新增功能],然後:
Search for OpenSSH Client, then select Install
Search for OpenSSH Server, then select Install
Open the Services desktop app. (Select Start, type services.msc in the search box, and then select the Service app or press ENTER.)
在詳細資料窗格中,按兩下 OpenSSH SSH Server。
On the General tab, from the Startup type drop-down menu, select Automatic and then select Ok.
To start the service, select Start.
Note
安裝 OpenSSH 伺服器後會建立並啟用名為 OpenSSH-Server-In-TCP
的防火牆規則。 這個規則會允許連接埠 22 上的輸入 SSH 流量。 如果未啟用此規則,而且此埠未開啟,將會拒絕或重設連線。
連線至 OpenSSH 伺服器
安裝之後,您可以從已安裝 OpenSSH 用戶端的 Windows 或 Windows Server 裝置連線到 OpenSSH Server。 從在 PowerShell 提示字元欄位執行下列命令。
ssh domain\username@servername
連上線之後,您會收到類似下列輸出的訊息。
The authenticity of host 'servername (10.00.00.001)' can't be established.
ECDSA key fingerprint is SHA256:(<a large string>).
Are you sure you want to continue connecting (yes/no)?
Entering yes adds that server to the list of known SSH hosts on your Windows client.
此時,服務會提示您輸入密碼。 基於安全性預防措施,密碼的字元不會在您輸入密碼時顯示。
線上之後,您應該會看到下列 Windows 命令殼層提示字元:
domain\username@SERVERNAME C:\Users\username>
解除安裝適用於 Windows 的 OpenSSH
使用 Windows 設定解除安裝 OpenSSH:
Open Settings, select System, then select Optional Features (also referred to as Manage optional features).
In the list, select OpenSSH Client or OpenSSH Server.
Select Uninstall.
如果服務在卸載時正在使用中,您應該重新啟動 Windows。
Next steps
現在您已完成安裝適用於 Windows 的 OpenSSH Server,以下是一些可協助您瞭解如何使用它的文章:
深入了解如何在 OpenSSH 金鑰管理中使用金鑰組以供驗證