Computer >> Hướng Dẫn Máy Tính >  >> Hệ Thống >> Máy Chủ Windows

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Giao thức Remote Desktop Protocol (RDP) cho phép bạn kết nối từ xa đến desktop của máy tính chạy Windows và làm việc với nó như thể đó là máy tính cục bộ của bạn. Mặc định, truy cập Remote Desktop bị tắt trong Windows. Trong bài viết này, chúng tôi sẽ trình bày cách bật và cấu hình truy cập RDP trên Windows 10/11 và Windows Server 2019/2022.

Cách Bật và Sử dụng Kết nối Remote Desktop trên Windows 10 hoặc 11?

Cách dễ nhất để bật Remote Desktop Connection trong Windows là dùng GUI Control Panel.

Mở thuộc tính hệ thống trong Control Panel hoặc chạy lệnh SystemPropertiesRemote.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Mở tab Remote Settings và bật tùy chọn Allow remote connection to this computer.

Vì lý do bảo mật, khuyến nghị chỉ cho phép kết nối từ client RDP hỗ trợ NLA (Allow connections only from computers running Remote Desktop with Network Level Authentication).

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Lưu thay đổi bằng cách nhấp OK.

Mặc định, chỉ thành viên của nhóm Administrators cục bộ mới có thể kết nối từ xa đến máy tính qua RDP. Nếu bạn muốn cho phép truy cập RDP cho user khác, nhấp Select Users.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Tất cả user bạn chỉ định ở đây sẽ được thêm vào nhóm local Remote Desktop Users. Bạn có thể hiển thị danh sách user trong nhóm bằng lệnh:

net localgroup "Remote Desktop Users"

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Thành viên trong nhóm này được cấp quyền logon từ xa.

Để thêm user mới vào nhóm truy cập RDP, chạy lệnh dưới:

net localgroup "Remote Desktop Users" /add a.williams

Trong build hiện tại của Windows 10 và Windows 11, hộp thoại System Properties cổ điển để bật RDP bị ẩn, và Microsoft khuyến nghị dùng bảng Settings mới:

  1. Mở Settings -> System —> Remote Desktop;
  2. Bật Enable Remote Desktop sang ON; Cách Bật Remote Desktop Protocol (RDP) trên Windows?
  3. Xác nhận bật RDP trên máy tính.
Lưu ý bạn không thể bật RDP trên Windows 10 Home. Dịch vụ Remote Desktop chỉ hoạt động trên Windows 10 Pro và Enterprise. Tuy nhiên, có cách giải quyết.

Bạn có thể bật RDP trên Windows 11 dùng ứng dụng Settings hiện đại. Đi đến System -> Remote Desktop -> Bật Remote Desktop bằng nút gạt.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Lưu ý mặc định hai tùy chọn được bật khi bạn bật Remote Desktop:

  • Keep my PC awake for connection when it is plugged in
  • Make my PC discoverable on private networks to enable automatic connection from a remote device

Nhấp Advanced settings. Ở đây bạn có thể bật Network Level Authentication cho kết nối RDP (khuyến nghị).

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Nếu Windows Defender Firewall được bật trên máy tính, hãy đảm bảo nó cho phép kết nối RDP đến. Mặc định cổng TCP 3389 dùng cho kết nối RDP, và build Windows mới cũng dùng UDP 3389 (xem bài về trường hợp màn hình đen thay vì desktop khi kết nối RDP).

Mở Control Panel và chọn Windows Defender Firewall. Mở danh sách quy tắc Windows Firewall mặc định bằng cách nhấp Allow an app or feature through Windows Firewall ở cột trái.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Đảm bảo quy tắc Remote Desktop được bật cho profile Private (mạng gia đình hoặc doanh nghiệp) và Public (mạng công cộng) nếu cần.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Tìm hiểu thêm về loại mạng và profile Windows Firewall ở đây.

Nếu muốn, bạn có thể đặt giới hạn (timeout) cho thời lượng phiên RDP bằng GPO.

Bây giờ bạn có thể kết nối từ xa đến máy tính này dùng client RDP. Windows có client RDP tích hợp – mstsc.exe. Nó lưu lịch sử kết nối RDP và hỗ trợ sao chép file giữa máy cục bộ và từ xa qua clipboard RDP.

Bạn cũng có thể dùng RDP connection manager, như RDCMan hoặc mRemoteNG, cũng như client thay thế.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Để thuận tiện cho user, bạn có thể lưu mật khẩu kết nối RDP trong Windows Credential Manager.

Bật RDP trên Windows bằng PowerShell

Bạn có thể nhanh chóng bật truy cập RDP trên Windows bằng vài lệnh PowerShell.

  1. Chạy PowerShell.exe với quyền administrator;
  2. Bật truy cập RDP qua registry bằng cmdlet Set-ItemProperty: Set-ItemProperty -Path 'HKLM:\System\CurrentControlSet\Control\Terminal Server' -name "fDenyTSConnections" -value 0 Để tắt RDP, đổi giá trị fDenyTSConnections thành 1.
  3. Cho phép kết nối RDP đến máy tính trong Windows Defender Firewall. Để làm vậy, bật quy tắc firewall sau: Enable-NetFirewallRule -DisplayGroup "Remote Desktop" Cách Bật Remote Desktop Protocol (RDP) trên Windows?
  4. Nếu muốn thêm user vào nhóm truy cập RDP cục bộ, chạy lệnh: Add-LocalGroupMember -Group "Remote Desktop Users" -Member a.williams

Để đảm bảo cổng RDP mở trên máy tính, dùng cmdlet Test-NetConnection:

Test-NetConnection -ComputerName wksde133 -CommonTCPPort RDP

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Bật Kết nối Remote Desktop trên Windows Server 2022/2019

Khác với phiên bản desktop Windows 10 (11), Windows Server hỗ trợ 2 kết nối RDP đồng thời mặc định. Các kết nối này dùng bởi administrator để quản lý server.

RDP được bật trên Windows Server theo cùng cách: dùng SystemPropertiesRemote, Server Manager, hoặc lệnh PowerShell mô tả ở trên.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Bạn có thể dùng Windows Server làm terminal server. Trong trường hợp này, nhiều user có thể đồng thời kết nối đến desktop của họ trên server. Để làm vậy, cài đặt và cấu hình vai trò Remote Desktop Session Host (RDSH) trên server. Để dùng nó, bạn phải mua và kích hoạt RDS CALs đặc biệt. Tìm hiểu thêm về cấp phép RDS.

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Cũng có thể dùng chứng chỉ SSL/TLS để bảo mật kết nối RDP.

Cách Bật RDP qua Group Policy (GPO) trong Domain Active Directory?

Nếu cần bật Remote Desktop trên nhiều máy tính cùng lúc, bạn có thể dùng Group Policy (GPO). Chúng ta giả định tất cả máy tính đã join vào domain Active Directory.

  1. Chạy console Group Policy Management (gpmc.msc);
  2. Tạo Group Policy Object mới (hoặc chỉnh sửa cái có sẵn) và liên kết nó với OU đích chứa máy tính hoặc server; Cách Bật Remote Desktop Protocol (RDP) trên Windows?
  3. Chuyển sang chế độ chỉnh sửa chính sách và đi đến phần GPO Computer Configuration -> Administrative Templates -> Windows Components -> Remote Desktop Services -> Remote Desktop Session Host -> Connections;
  4. Tìm và bật tham số Allow Users to connect remotely by using Remote Desktop Services; Cách Bật Remote Desktop Protocol (RDP) trên Windows?
  5. Cập nhật cài đặt GPO trên client;
  6. Sau khi áp dụng chính sách, bạn sẽ có thể kết nối đến tất cả máy tính qua RDP (chính sách sẽ áp dụng cho cả client desktop chạy Windows 10/11 và Windows Server). Nếu cần, bạn có thể nhắm chính sách RDP đến máy tính cụ thể bằng bộ lọc WMI GPO;
  7. Nếu Windows Defender Firewall được bật trên máy tính, bạn cần cho phép lưu lượng RDP cho domain profile trong cùng GPO. Để làm vậy, kích hoạt quy tắc Windows Firewall: Allow inbound Remote Desktop Exceptions (nằm trong Computer Configuration -> Administrative Templates -> Network -> Network Connections -> Windows Firewall -> Domain Profile). Cách Bật Remote Desktop Protocol (RDP) trên Windows?
Tìm hiểu thêm về cách cấu hình quy tắc Windows Firewall bằng GPO.

Bật Remote Desktop (RDP) Từ Xa trên Windows

Cũng có thể bật RDP từ xa trên bất kỳ máy tính chạy Windows. Để làm vậy, bạn phải có truy cập từ xa đến máy tính (qua PowerShell hoặc WMI) và tài khoản của bạn phải là thành viên của nhóm Administrators cục bộ trên máy tính từ xa.

Bạn có thể bật RDP từ xa qua registry. Để làm vậy, dịch vụ Remote Registry phải được bật trên máy tính từ xa (nó bị tắt mặc định). Để chạy dịch vụ:

  1. Mở console quản lý dịch vụ (services.msc);
  2. Chọn Connect to another computer và chỉ định tên máy tính từ xa; Cách Bật Remote Desktop Protocol (RDP) trên Windows?
  3. Tìm dịch vụ Remote Registry trong danh sách, đổi kiểu khởi động thành Manual, và khởi động dịch vụ. Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Cùng việc có thể làm từ xa từ command prompt bằng công cụ sc tích hợp (cho phép tạo, quản lý, xóa dịch vụ Windows):

sc \\wksde133 config RemoteRegistry start= demand
sc \\wksde133 start RemoteRegistry

Cách Bật Remote Desktop Protocol (RDP) trên Windows?

Sau đó trên máy cục bộ:

  1. Chạy Registry Editor (regedit.exe);
  2. Chọn Connect Network Registry trong menu File;
  3. Chỉ định tên hoặc IP máy tính từ xa bạn muốn bật RDP;
  4. Đi đến khóa reg HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Terminal Server;
  5. Tìm tham số fDenyTSConnections (REG_DWORD). Nếu không tìm thấy, tạo nó. Đổi giá trị thành 0 để bật RDP. Cách Bật Remote Desktop Protocol (RDP) trên Windows?
Để tắt truy cập RDP, bạn cần đổi giá trị fDenyTSConnections thành 1.

Sau đó máy tính từ xa có thể truy cập qua RDP ngay lập tức mà không cần khởi động lại.

Nhưng nhanh hơn là bật RDP trong registry máy từ xa qua command prompt:

REG ADD "\\wksde133\HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 0 /f

Nếu PowerShell remoting được cấu hình trên máy từ xa, bạn có thể chạy lệnh từ xa trên nó qua Invoke-Command:

Invoke-Command -Computername wksde133 -ScriptBlock {Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server" -Name "fDenyTSConnections" –Value 0}

Nếu OpenSSH server cài trong Windows, bạn có thể kết nối đến nó bằng bất kỳ SSH client nào, và thay đổi registry trong phiên SSH.

Cũng có thể kết nối đến máy từ xa và bật RDP qua WMI:

$computername = “wksde133”
(Get-WmiObject -Class Win32_TerminalServiceSetting -Namespace root\CIMV2\TerminalServices -Computer $computername -Authentication 6).SetAllowTSConnections(1,1)

Cách Bật Remote Desktop Protocol (RDP) trên Windows?