Last active
January 25, 2026 20:43
-
-
Save truongtpa/d8296d283392a75e6751cc65c8922a96 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # Script cài đặt xrdp cho Ubuntu 22.04 Desktop | |
| # Tác giả: An-Truong | |
| # Ngày: 2026-01-25 | |
| echo "=========================================" | |
| echo "Cài đặt xrdp cho Ubuntu 22.04 Desktop" | |
| echo "=========================================" | |
| # Kiểm tra quyền root | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "Vui lòng chạy script với quyền sudo" | |
| echo "Sử dụng: sudo bash install_xrdp.sh" | |
| exit 1 | |
| fi | |
| # Cập nhật package list | |
| echo "" | |
| echo "[1/7] Cập nhật package list..." | |
| apt update | |
| # Cài đặt xrdp | |
| echo "" | |
| echo "[2/7] Cài đặt xrdp..." | |
| apt install xrdp -y | |
| # Thêm user xrdp vào group ssl-cert | |
| echo "" | |
| echo "[3/7] Cấu hình quyền cho xrdp..." | |
| adduser xrdp ssl-cert | |
| # Backup file cấu hình gốc | |
| echo "" | |
| echo "[4/7] Backup file cấu hình..." | |
| cp /etc/xrdp/startwm.sh /etc/xrdp/startwm.sh.backup | |
| # Cấu hình cho GNOME Ubuntu 22.04 | |
| echo "" | |
| echo "[5/7] Cấu hình GNOME cho xrdp..." | |
| cat > /etc/xrdp/startwm.sh << 'EOF' | |
| #!/bin/sh | |
| # xrdp X session start script (c) 2015, 2017, 2021 mirabilos | |
| # published under The MirOS Licence | |
| # Cấu hình cho Ubuntu 22.04 GNOME | |
| export GNOME_SHELL_SESSION_MODE=ubuntu | |
| export XDG_CURRENT_DESKTOP=ubuntu:GNOME | |
| export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg | |
| unset DBUS_SESSION_BUS_ADDRESS | |
| unset XDG_RUNTIME_DIR | |
| if test -r /etc/profile; then | |
| . /etc/profile | |
| fi | |
| test -x /etc/X11/Xsession && exec /etc/X11/Xsession | |
| exec /bin/sh /etc/X11/Xsession | |
| EOF | |
| chmod +x /etc/xrdp/startwm.sh | |
| # Cấu hình firewall | |
| echo "" | |
| echo "[6/7] Cấu hình firewall..." | |
| ufw allow 3389/tcp | |
| ufw reload | |
| # Restart và enable xrdp | |
| echo "" | |
| echo "[7/7] Khởi động xrdp service..." | |
| systemctl restart xrdp | |
| systemctl enable xrdp | |
| # Kiểm tra status | |
| echo "" | |
| echo "=========================================" | |
| echo "Kiểm tra trạng thái xrdp:" | |
| echo "=========================================" | |
| systemctl status xrdp --no-pager | |
| # Lấy IP address | |
| echo "" | |
| echo "=========================================" | |
| echo "Thông tin kết nối RDP:" | |
| echo "=========================================" | |
| IP_ADDRESS=$(hostname -I | awk '{print $1}') | |
| echo "IP Address: $IP_ADDRESS" | |
| echo "Port: 3389" | |
| echo "Username: $(logname 2>/dev/null || echo '<ubuntu_username>')" | |
| echo "" | |
| echo "Từ Windows, mở Remote Desktop (mstsc) và kết nối tới:" | |
| echo " $IP_ADDRESS:3389" | |
| echo "" | |
| echo "⚠️ LƯU Ý: Phải LOGOUT khỏi Desktop trước khi RDP!" | |
| echo "=========================================" | |
| echo "Cài đặt hoàn tất! ✅" | |
| echo "=========================================" | |
| #!/bin/bash | |
| # Script fix lỗi login xrdp tự động logout Ubuntu 22.04 | |
| echo "=========================================" | |
| echo "Fix lỗi xrdp tự động logout" | |
| echo "=========================================" | |
| # Fix 1: Tắt Wayland, bắt buộc dùng Xorg | |
| echo "" | |
| echo "[1/5] Tắt Wayland, chuyển sang Xorg..." | |
| sudo sed -i 's/#WaylandEnable=false/WaylandEnable=false/' /etc/gdm3/custom.conf | |
| # Fix 2: Cấu hình startwm.sh đúng cách | |
| echo "" | |
| echo "[2/5] Cấu hình lại startwm.sh..." | |
| sudo cat > /etc/xrdp/startwm.sh << 'EOF' | |
| #!/bin/sh | |
| # Fix for Ubuntu 22.04 GNOME | |
| export GNOME_SHELL_SESSION_MODE=ubuntu | |
| export XDG_CURRENT_DESKTOP=ubuntu:GNOME | |
| export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg | |
| export XDG_DATA_DIRS=/usr/share/ubuntu:/usr/local/share:/usr/share:/var/lib/snapd/desktop | |
| unset DBUS_SESSION_BUS_ADDRESS | |
| unset XDG_RUNTIME_DIR | |
| if test -r /etc/profile; then | |
| . /etc/profile | |
| fi | |
| if test -r ~/.profile; then | |
| . ~/.profile | |
| fi | |
| test -x /etc/X11/Xsession && exec /etc/X11/Xsession | |
| exec /bin/sh /etc/X11/Xsession | |
| EOF | |
| sudo chmod +x /etc/xrdp/startwm.sh | |
| # Fix 3: Tạo file .xsessionrc cho user | |
| echo "" | |
| echo "[3/5] Tạo file .xsessionrc cho user..." | |
| cat > ~/.xsessionrc << 'EOF' | |
| export GNOME_SHELL_SESSION_MODE=ubuntu | |
| export XDG_CURRENT_DESKTOP=ubuntu:GNOME | |
| export XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg | |
| EOF | |
| # Fix 4: Cấu hình polkit | |
| echo "" | |
| echo "[4/5] Cấu hình polkit..." | |
| sudo cat > /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla << 'EOF' | |
| [Allow Colord all Users] | |
| Identity=unix-user:* | |
| Action=org.freedesktop.color-manager.create-device;org.freedesktop.color-manager.create-profile;org.freedesktop.color-manager.delete-device;org.freedesktop.color-manager.delete-profile;org.freedesktop.color-manager.modify-device;org.freedesktop.color-manager.modify-profile | |
| ResultAny=no | |
| ResultInactive=no | |
| ResultActive=yes | |
| EOF | |
| # Fix 5: Restart services | |
| echo "" | |
| echo "[5/5] Restart services..." | |
| sudo systemctl restart xrdp | |
| sudo systemctl restart gdm3 | |
| echo "" | |
| echo "=========================================" | |
| echo "✅ Hoàn tất! Hãy thử:" | |
| echo "1. LOGOUT hoàn toàn khỏi Ubuntu Desktop" | |
| echo "2. Kết nối RDP từ Windows" | |
| echo "3. Chọn session type: Xorg" | |
| echo "=========================================" | |
| echo "IP: $(hostname -I | awk '{print $1}'):3389" | |
| echo "=========================================" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment