0%

20230208 在 Windows 2019 安裝 SFTP Server

在 Windows 2019 安裝 SFTP Server

安裝過程

使用 系統管理員 開啟 PowerShell

依序執行下列 commands 即可

1
Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'
1
2
3
4
5
# 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
1
2
3
4
5
6
7
8
9
10
11
12
13
# 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 | 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."
}

安裝過程複製

InstallSSH

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
Windows PowerShell
著作權 (C) Microsoft Corporation. 著作權所有,並保留一切權利。

PS C:\Users\Administrator> Get-WindowsCapability -Online | Where-Object Name -like 'OpenSSH*'


Name : OpenSSH.Client~~~~0.0.1.0
State : Installed

Name : OpenSSH.Server~~~~0.0.1.0
State : NotPresent



PS C:\Users\Administrator> Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0


Path :
Online : True
RestartNeeded : False



PS C:\Users\Administrator> Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0


Path :
Online : True
RestartNeeded : False



PS C:\Users\Administrator> # Start the sshd service
PS C:\Users\Administrator> Start-Service sshd
PS C:\Users\Administrator>
PS C:\Users\Administrator> # OPTIONAL but recommended:
PS C:\Users\Administrator> Set-Service -Name sshd -StartupType 'Automatic'
PS C:\Users\Administrator>
PS C:\Users\Administrator> # Confirm the Firewall rule is configured. It should be created automatically by setup. Run the following to verify
PS C:\Users\Administrator> 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."
>> }
Firewall rule 'OpenSSH-Server-In-TCP' has been created and exists.
PS C:\Users\Administrator>

安裝完成後,可使用 WinSCP 連線

WinSCP

教學文章

安裝OpenSSH | Microsoft Learn

補充

在我的空閒時間裡,我會不斷開發高效率、易用的小工具,讓使用者能夠享受到更好的體驗。
如果您有任何特定的服務需求,或是想要委託我開發獨一無二的程式、其他形式的合作,
歡迎透過電子郵件 E-Mail 與我聯繫。我會竭盡所能地為您提供最佳的服務。