RHEL 7.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 RHEL7.x.

RHEL 7.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. 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
    …
  3. 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 .vnc/startwm.sh
    (sleep 3; cp ${HOME}/.vnc/passwd ${HOME}/.vnc/sesman_passwd-${USER}@$(hostname)$(echo "$DISPLAY" | sed -E "s/.*:([0-9]{1,})\.0/:\1/"))&
    /etc/X11/xinit/Xsession

    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 xrdp password file, in the sesman-passwd format, may differ depending on the system.

  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

      Note: If you encounter dependency issues with Xvfb, the following process will resolve the issue.

      $ sudo yum install xorg-x11-server-common
      $ sudo yum install http://mirror.chpc.utah.edu/pub/centos/7.9.2009/os/x86_64/Packages/xorg-x11-server-Xvfb-1.20.4-10.el7.x86_64.rpm
      $ 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]*\).*')`&
      /etc/X11/xinit/Xsession

      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: (Required) This option allows for keys to be inputted continuously.

      • -shared: (Optional) Screen sharing option.

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

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

      • -rfbport: (Required) 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. Input of the password is required.

  3. Check the $DISPLAY value in a terminal.
    e.g.) :30.0 => 30 (Remember the number 30. 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 vnc-any as the session type.

  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.) 30 => 5930

  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 (username does not need to be entered).

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. Input of the password is required.

  3. Check the $DISPLAY value in a terminal.

    $ echo $DISPLAY
    :13.0
    $ 

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

  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 vnc-any as the session type.

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

  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 (username does not need to be entered).



Example of an xrdp.ini for Pausing and Resuming

...
[Xorg]
name=Xorg
lib=libxup.so
username=ask
password=ask
ip=127.0.0.1
port=-1
code=20

[Xvnc]
name=Xvnc
lib=libvnc.so
username=ask
password=ask
ip=127.0.0.1
port=-1

[vnc-reconnect]
name=vnc-reconnect
lib=libvnc.so
ip=localhost
port=ask59
username=na
password=ask

[vnc-any]
name=vnc-any
lib=libvnc.so
ip=ask
port=ask5900
username=na
password=ask
#pamusername=asksame
#pampassword=asksame
#pamsessionmng=127.0.0.1
#delay_ms=2000
...

Note: In the example above "vnc-reconnect" was created to easily reconnect to the Xorg or Xvnc session created with Xrdp.