Cấu hình SSH Server và SSH Client trên Windows Server 2019

Cấu hình SSH Server trên Windows Server 2019

1. Chạy Powershell với quyền admin và cấu hình SSH server như sau:

PowerShell
Copyright (C) Microsoft Corporation. All rights reserved.

# get available name of OpenSSH
PS C:\Users\Administrator> Get-WindowsCapability -Online | ? Name -like 'OpenSSH*' 

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

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

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

Path          :
Online        : True
RestartNeeded : False

# start sshd service
PS C:\Users\Administrator> Start-Service -Name "sshd" 

# set [Automatic] for Startup
PS C:\Users\Administrator> Set-Service -Name "sshd" -StartupType Automatic 

# verify
PS C:\Users\Administrator> Get-Service -Name "sshd" | Select-Object * 

Name                : sshd
RequiredServices    : {}
CanPauseAndContinue : False
CanShutdown         : False
CanStop             : True
DisplayName         : OpenSSH SSH Server
DependentServices   : {}
MachineName         : .
ServiceName         : sshd
ServicesDependedOn  : {}
ServiceHandle       : SafeServiceHandle
Status              : Running
ServiceType         : Win32OwnProcess
StartType           : Automatic
Site                :
Container           :


# if Windows Firewall is running, allow 22/TCP
PS C:\Users\Administrator> New-NetFirewallRule -Name "SSH" `
-DisplayName "SSH" `
-Description "Allow SSH" `
-Profile Any `
-Direction Inbound `
-Action Allow `
-Protocol TCP `
-Program Any `
-LocalAddress Any `
-RemoteAddress Any `
-LocalPort 22 `
-RemotePort Any 

Name                  : SSH
DisplayName           : SSH
Description           : Allow SSH
DisplayGroup          :
Group                 :
Enabled               : True
Profile               : Any
Platform              : {}
Direction             : Inbound
Action                : Allow
EdgeTraversalPolicy   : Block
LooseSourceMapping    : False
LocalOnlyMapping      : False
Owner                 :
PrimaryStatus         : OK
Status                : The rule was parsed successfully from the store. (65536)
EnforcementStatus     : NotApplicable
PolicyStoreSource     : PersistentStore
PolicyStoreSourceType : Local

2. Mở Start > Settings.

Mở Start > Settings
Mở Start > Settings

3. Kích vào Apps.

Kích vào Apps
Kích vào Apps

4. Nhấp vào Manage optional features.

Nhấp vào Manage optional features
Nhấp vào Manage optional features

5. Nhấp vào Add a feature.

Nhấp vào Add a feature
Nhấp vào Add a feature

6. Chọn OpenSSH Server và nhấp vào nút Install.

Chọn OpenSSH Server
Chọn OpenSSH Server

7. Sau khi hoàn tất cài đặt, OpenSSH Server sẽ được thêm vào các service. Khởi động nó và thay đổi Startup thành Automatic.

OpenSSH Server sẽ được thêm vào các service
OpenSSH Server sẽ được thêm vào các service

8. Nếu Windows Firewall đang chạy, hãy cho phép cổng service SSH (22/TCP).

Cho phép cổng service SSH (22/TCP)
Cho phép cổng service SSH (22/TCP)

Cấu hình SSH Client trên Windows Server 2019

1. Trên Windows Server 2019, OpenSSH Client được cài đặt theo mặc định. Nhưng nếu nó chưa được cài đặt, hãy cài đặt từ Start > Settings > Apps > >Manage optional features > Add a feature > OpenSSH Client.

Cài đặt OpenSSH Client
Cài đặt OpenSSH Client

2. Có thể sử dụng lệnh client ssh như sau trên PowerShell hoặc Command Prompt:

PS > ssh (username)@(Hostname hoặc địa chỉ IP của SSH server)
Sử dụng lệnh client ssh
Sử dụng lệnh client ssh

3. Bạn cũng có thể đăng nhập vào Linux Host mà SSH server đang chạy.

Đăng nhập vào Linux Host mà SSH server đang chạy
Đăng nhập vào Linux Host mà SSH server đang chạy

4. Bạn cũng có thể sử dụng lệnh scp và lệnh sftp để truyền file SSH.

Thứ Hai, 22/03/2021 11:03
44 👨 6.244
1 Bình luận
Sắp xếp theo
  • Nguyễn Văn Phương
    Nguyễn Văn Phương

    Cảm ơn rất nhiều ạ, kiến thức rất hay ạ

    Thích Phản hồi 10:26 26/07