需要手动安装 Ubuntu20.4

    1. #!/bin/bash
    2. #
    3. # This script is for Ubuntu 20.04 Focal Fossa to download and install XRDP+XORGXRDP via
    4. # source.
    5. #
    6. # Major thanks to: http://c-nergy.be/blog/?p=11336 for the tips.
    7. #
    8. ###############################################################################
    9. # Use HWE kernel packages
    10. #
    11. HWE=""
    12. #HWE="-hwe-20.04"
    13. ###############################################################################
    14. # Update our machine to the latest code if we need to.
    15. #
    16. if [ "$(id -u)" -ne 0 ]; then
    17. echo 'This script must be run with root privileges' >&2
    18. exit 1
    19. fi
    20. apt update && apt upgrade -y
    21. if [ -f /var/run/reboot-required ]; then
    22. echo "A reboot is required in order to proceed with the install." >&2
    23. echo "Please reboot and re-run this script to finish the install." >&2
    24. exit 1
    25. fi
    26. ###############################################################################
    27. # XRDP
    28. #
    29. # Install hv_kvp utils
    30. apt install -y linux-tools-virtual${HWE}
    31. apt install -y linux-cloud-tools-virtual${HWE}
    32. # Install the xrdp service so we have the auto start behavior
    33. apt install -y xrdp
    34. systemctl stop xrdp
    35. systemctl stop xrdp-sesman
    36. # Configure the installed XRDP ini files.
    37. # use vsock transport.
    38. sed -i_orig -e 's/port=3389/port=vsock:\/\/-1:3389/g' /etc/xrdp/xrdp.ini
    39. # use rdp security.
    40. sed -i_orig -e 's/security_layer=negotiate/security_layer=rdp/g' /etc/xrdp/xrdp.ini
    41. # remove encryption validation.
    42. sed -i_orig -e 's/crypt_level=high/crypt_level=none/g' /etc/xrdp/xrdp.ini
    43. # disable bitmap compression since its local its much faster
    44. sed -i_orig -e 's/bitmap_compression=true/bitmap_compression=false/g' /etc/xrdp/xrdp.ini
    45. # Add script to setup the ubuntu session properly
    46. if [ ! -e /etc/xrdp/startubuntu.sh ]; then
    47. cat >> /etc/xrdp/startubuntu.sh << EOF
    48. #!/bin/sh
    49. export GNOME_SHELL_SESSION_MODE=ubuntu
    50. export XDG_CURRENT_DESKTOP=ubuntu:GNOME
    51. exec /etc/xrdp/startwm.sh
    52. EOF
    53. chmod a+x /etc/xrdp/startubuntu.sh
    54. fi
    55. # use the script to setup the ubuntu session
    56. sed -i_orig -e 's/startwm/startubuntu/g' /etc/xrdp/sesman.ini
    57. # rename the redirected drives to 'shared-drives'
    58. sed -i -e 's/FuseMountName=thinclient_drives/FuseMountName=shared-drives/g' /etc/xrdp/sesman.ini
    59. # Changed the allowed_users
    60. sed -i_orig -e 's/allowed_users=console/allowed_users=anybody/g' /etc/X11/Xwrapper.config
    61. # Blacklist the vmw module
    62. if [ ! -e /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf ]; then
    63. echo "blacklist vmw_vsock_vmci_transport" > /etc/modprobe.d/blacklist-vmw_vsock_vmci_transport.conf
    64. fi
    65. #Ensure hv_sock gets loaded
    66. if [ ! -e /etc/modules-load.d/hv_sock.conf ]; then
    67. echo "hv_sock" > /etc/modules-load.d/hv_sock.conf
    68. fi
    69. # Configure the policy xrdp session
    70. cat > /etc/polkit-1/localauthority/50-local.d/45-allow-colord.pkla <<EOF
    71. [Allow Colord all Users]
    72. Identity=unix-user:*
    73. 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
    74. ResultAny=no
    75. ResultInactive=no
    76. ResultActive=yes
    77. EOF
    78. # reconfigure the service
    79. systemctl daemon-reload
    80. systemctl start xrdp
    81. #
    82. # End XRDP
    83. ###############################################################################
    84. echo "Install is complete."
    85. echo "Reboot your machine to begin using XRDP."

    以上命令执行后需要 设置虚拟机支持会话增强 (在完全关闭的状态执行,连接虚拟机的界面也关掉 )

    1. Set-VM -VMName 'ubuntu' -EnhancedSessionTransportType HvSocket