CentOS 8.x - XRDP Enabling Multiple Sessions and Pause/Resume

If you haven't already, please refer to the URL below for how to install and use XRDP in CentOS 8.x.

CentOS 8.x - XRDP Installation and Configuration

Table of Contents

Configurations to Enable Multiple Sessions

  1. Set user Window Manager settings in /etc/xrdp/sesman.ini as

    $ sudo vi /etc/xrdp/sesman.ini
    ...
    [Globals]
    …
    EnableUserWindowManager=true
    UserWindowManager=.vnc/startwm.sh
    ...

    Note: To apply the Window Manager to all users, assign startwm.sh to DefaultWindowManager. The description of sesman.ini states that a relative path to /etc/xrdp is sufficient, but this may not work depending on the system, so use an absolute path such as /etc/xrdp/startwm.sh.

    $ sudo vi /etc/xrdp/sesman.ini
    EnableUserWindowManager=true
    ;UserWindowManager=.vnc/startwm.sh
    ; Give in full path or relative path to /etc/xrdp
    DefaultWindowManager=/etc/xrdp/startwm.sh
  2. For convenience, edit /etc/xrdp/xrdp.ini and create a standard vnc session strictly for reconnecting.

    $ sudo vi /etc/xrdp/xrdp.ini...; Generic VNC Proxy
    ; Tailor this to specific hosts and VNC instances by specifying an ip
    ; and port and setting a suitable name.
    [vnc-reconnect]
    name=reconnect
    lib=libvnc.so
    ip=localhost
    port=ask59
    username=na
    password=ask
    ...
  3. Change the Policy to UBC in /etc/xrdp/sesman.ini (UBC means User, Bit Per Pixel, Connect. A new session will be created upon every connection.)

    $ sudo vi /etc/xrdp/sesman.ini
    …
    [Sessions]
    …
    Policy=UBC
    …
  4. The DBUS setting is required to allow the same user to have multiple sessions. Add the following to the top of the /etc/X11/xint/Xsession file.

    $ sudo vi /etc/X11/xinit/Xsession
    #!/usr/bin/bash
    export $(dbus-launch)
    ...

    Note: This command can be executed in startwm.sh (mentioned above), but this setting is necessary for multiple sessions, even when connecting via XDMCP, etc., so it is recommended you set it in the Xsession file that is commonly used with xrdp.

Configurations to Enable Reconnecting to Sessions

  1. After creating the startwm.sh file in the path defined in step 1 of Configurations to Enable Multiple Sessions, add the following content

    $ vi /etc/xrdp/startwm.sh
    #!/usr/bin/bash
    (sleep 3; cp ${HOME}/.vnc/passwd ${HOME}/.vnc/sesman_passwd-${USER}@${HOSTNAME}${DISPLAY/.0/})&
    /etc/X11/xinit/Xsession
    exit

    Explanation

    • When reconnecting, the vnc client cannot process the xrdp password, so reconnection is not possible. This replaces the xrdp password file with a password file that the vnc client can understand
    • The reason for the delay is that when xrdp's session manager (sesman) runs Xsession and shows the corresponding session, it accesses the sesman_passwd-user@host:display password file. If this file has been replaced in advance, the corresponding session's screen cannot be retrieved and only the Xvnc session would run.
      The full process is as follows: Run Xvnc session (user password required) → Connect to Xvnc session (user password required) → Replace xrdp session password (vnc password) → Reconnect with vnc viewer (use vnc password)

  2. For each user who will use Xrdp, use the vncpasswd command to create the $HOME/.vnc/passwd file described above.

    $ vncpasswd
    Password: 
    Verify: 
    Would you like to enter a view-only password (y/n)? n 
    A view-only password is not used

    NOTE: Many VNCs, including tigervnc, only use up to 8 characters for passwords. Even if you enter more than 8 characters, only up to 8 characters are saved. Also, some vncpasswd programs require more than 6 characters. If you want to create a password with less than 6 characters, you can use the 'vncpasswd -f >passwd' command.

  3. With Xrdp, you can either utilize Xorg sessions or Xvnc sessions. If you will only utilize Xvnc sessions, you can skip this step. For Xorg sessions, the following process is required.

    1. Install and configure x11vnc

      $ sudo yum install x11vnc
    2. Set x11vnc to run automatically in $HOME/.vnc/startwm.sh.

      $ $ vi .vnc/startwm.sh
      cp ${HOME}/.vnc/passwd ${HOME}/.vnc/sesman_passwd-${USER}@$(hostname)$(echo "$DISPLAY" | sed -E "s/.*:([0-9]{1,})\.0/:\1/")
      x11vnc -repeat -display $DISPLAY -shared -forever -rfbauth $HOME/.vnc/passwd -rfbport 59`printf %02d $(expr match "$DISPLAY" '.*:\([0-9]*\).*')`&
      ...

      Explanation:

      • x11vnc allows you to connect to the Xorg server via vnc.

      • The goal of this command is to make the values of the Xorg display number and the vnc port number the same.

      • -repeat: This option allows for keys to be inputted continuously.

      • -shared: Screen sharing option.

      • -forever: Option to wait for the next connection even if the vnc session is closed.

      • -rfbauth: Specifies the file to use as the connection password for the vnc session.

      • -rfbport: Port number to listen for the vnc connection. The above command links this with the value of $DISPLAY.

Launch a New Xrdp Session and Reconnect

You can choose either Xvnc or Xorg as the session type for the Xrdp session.

Create and pause an Xvnc session (Stays running in the background)

  1. From Xmanager, launch an RDP session. Select Xvnc as the session type.


  2. Enter your username and password (user password) and initialize the session.

  3. Check the $DISPLAY value in a terminal.
    e.g.) :11.0 => 11 (Remember the number 11. The screen number, .0, can be ignored)


  4. To pause a session, close the Xmanager RDP window of Xmanager without logging out. If you log out, the session will terminate.

Reconnect to an existing Xvnc session

  1. From Xmanager, launch the relevant RDP session, and select the "reconnect" session created in step 2 of the Configurations to Enable Multiple Sessions section above.

  2. In the Port field, enter the number obtained by adding 5900 to the display number in step 3 of the previous section.
    e.g.) 11 => 5911

  3. In the Password field, enter the password determined by the vncpasswd command in step 2 of the Configurations to Enable Reconnecting to Sessions section above.

Create and pause an Xorg session (Stays running in the background)

  1. From Xmanager, launch an RDP session. Select Xorg as the session type.


  2. Enter your username and password (user password) and initialize the session.

  3. Check the $DISPLAY value in a terminal.

    In the example above, the $DISPLAY is :11.0. Previously, we had used the x11vnc command to link the display number (11) and the VNC standby port. Add 5900 to this value. Thus, in this example, VNC will listen at number 5911.

  4. To pause a session, close the Xmanager RDP window of Xmanager without logging out. If you log out, the session will terminate.

Reconnect to an existing Xorg session

  1. From Xmanager, launch the relevant RDP session, and select the "reconnect" session created in step 2 of the Configurations to Enable Multiple Sessions section above.

  2. In the Port field, enter the number obtained by adding 5900 to the display number of step 3 in the previous section.
    e.g.) 11 => 5911

  3. In the Password field , enter the password determined by the vncpasswd command in step 2 of the Configurations to Enable Reconnecting to Sessions section above.