Mint 21.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 Mint 21.x

Mint 21.2 - XRDP Installation and Configuration

Table of Contets

Configurations to Enable Multiple Sessions

  1. Set user wm (Window Manager) settings in /etc/xrdp/sesman.ini as follows:

    $ sudo vi /etc/xrdp/sesman.ini
    ...
    [Globals]
    …
    EnableUserWindowManager=true
    ; Give in relative path to user's home directory
    UserWindowManager=.vnc/startwm.sh => This is a relative path to $HOME.
    ; Give in full path or relative path to /etc/xrdp
    DefaultWindowManager=startwm.sh => Path relative to /etc/xrdp.
    ...
  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. DBUS settings are required to allow the same user to have multiple sessions. Add the following to the top of the /etc/X11/Xsession file.

    $ which dbus-launch || sudo apt install dbus-x11
    $ sudo vi /etc/X11/Xsession
    #!/usr/bin/bash
    export $(dbus-launch)
    ...

Configurations to Enable Reconnecting to Sessions

  1. Edit the startwm.sh file created in the path defined in step 1 of Configurations to Enable Multiple Sessions above. (If it does not exist, create it.)

    $ sudo vi .vnc/startwm.sh
    #!/bin/sh
    # xrdp X session start script (c) 2015, 2017, 2021 mirabilos
    # published under The MirOS Licence
    
    # Rely on /etc/pam.d/xrdp-sesman using pam_env to load both
    # /etc/environment and /etc/default/locale to initialise the
    # locale and the user environment properly.
    
    if test -r /etc/profile; then
            . /etc/profile
    fi
    
    if test -r $HOME/.profile; then
            . $HOME/.profile
    fi
    
    #test -x /etc/X11/Xsession && exec /etc/X11/Xsession # => Delete or comment out
    #exec /bin/sh /etc/X11/Xsession # => Delete or comment out
    
    ######### added part #############
    # For reconnecting, change the password created with the vncpasswd command. The vncpasswd command only recognizes 8 characters, so if the user password exceeds 8 characters, you may not be able to connect to the session after executing the xrdp session.
    (sleep 3; cp ${HOME}/.vnc/passwd ${HOME}/.vnc/sesman_passwd-${USER}@$(hostname)$(echo "$DISPLAY" | sed -E "s/.*:([0-9]{1,})\.0/:\1/"))&
    
    if [ -f "$HOME/.vnc/startwm.sh" ] && [ -x "$HOME/.vnc/startwm.sh" ]; then
            $HOME/.vnc/startwm.sh
    else 
            exec /bin/sh /etc/X11/Xsession
    fi
  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
  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 apt install x11vnc
    2. Set x11vnc to run automatically in /etc/xrdp/startwm.sh.

      $ sudo vi /etc/xrdp/startwm.sh
      #!/bin/sh
      ...
      
      ######### x11vnc 관련 추가되는 부분Added parts related to x11vnc #############
      x11vnc -repeat -display $DISPLAY -shared -forever -rfbauth $HOME/.vnc/passwd -rfbport 59`printf %02d $(expr match "$DISPLAY" '.*:\([0-9]*\).*')`&
      
      ######### added part #############
      (sleep 3; cp ${HOME}/.vnc/passwd ${HOME}/.vnc/sesman_passwd-${USER}@$(hostname)$(echo "$DISPLAY" | sed -E "s/.*:([0-9]{1,})\.0/:\1/"))&
      
      if [ -f "$HOME/.vnc/startwm.sh" ] && [ -x "$HOME/.vnc/startwm.sh" ]; then
              $HOME/.vnc/startwm.sh
      else 
              exec /bin/sh /etc/X11/Xsession
      fi

      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.) :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 above.
    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.

  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 above.

    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).