List current xvnc sessions in xrdp so you can reconnect to your old one


{ echo "user pid Xdisplay port"; { ps -ef | awk '/Xvnc :[[:digit:]]+/ {print $1,$2,$9}' | while read tu tpid tvnc; do sudo netstat -tlpn | awk -v "tpid=${tpid}" '$0 ~ tpid {print $4;}' | sed -r -e 's/^.*://;' -e "s/^/${tu} ${tpid} ${tvnc} /;" ; done ; } | sort -k3 ; } | column -c4 -t

The story

I connected to a gnome session on a terminal server, and disconnected. I wanted to reconnect to my current session, but apparently I got a new X session. After some research, I learned you can configure xrdp to prompt for the port number so you can get back to the previous session. However, then you have to know what to type in. After doing a manual ps and netstat, I found some useful numbers. What I needed to enter was the tcp port number, so 5919.

The explanation

You can have an entry in the /etc/xrdp/xrdp.ini file like the following block.


When you connect over RDP, select the “Reconnect” module and type in a port number, which you can find from the output of the oneliner.

{ echo "user pid Xdisplay port"; { ps -ef | awk '/Xvnc :[[:digit:]]+/ {print $1,$2,$9}' | while read tu tpid tvnc; do sudo netstat -tlpn | awk -v "tpid=${tpid}" '$0 ~ tpid {print $4;}' | sed -r -e 's/^.*://;' -e "s/^/${tu} ${tpid} ${tvnc} /;" ; done ; } | sort -k3 ; } | column -c4 -t
user       pid    Xdisplay  port
mjohnso    11448  :17       5917
mjohnso    12939  :18       5918
bgstack15  1219   :19       5919




Xfce on Xrdp on Fedora 26


This post will demonstrate how to set up a Fedora installation to act as a terminal server that serves desktops over RDP. This will allow Windows computers to connect to it, as well as a GNU/Linux system running xfreerdp clients.
These instructions should be easy to follow on any RHEL-based distros, and easily adapted to others. The copy-paste segments have been tested on Fedora 26 but the accompanying instructions should guide you in deploying a terminal server on a broad range of GNU/Linux environments.

How to set up xrdp on Fedora

Ensure your desktop environment is installed. For CentOS 7 that would be something similar to yum groupinstall “Server with gui” or yum groupinstall xfce.
Install the components necessary for rdp and vnc. When the rdp server allows a user to connect, the user connects to a X windows session in VNC.

yum -y install xrdp tigervnc-server

Set up a firewall rule for the RDP port.

tf=/lib/firewalld/services/xrdp.xml; touch "${tf}"; chmod 0644 "${tf}"
cat <<EOF >"${tf}"
<?xml version="1.0" encoding="utf-8"?>
  <short>Remote Desktop Protocol (RDP)</short>
  <description>A RDP service that serves X desktop sessions. Using this allows a Windows client to connect using the built-in mstsc utility!</description>
  <port protocol="tcp" port="3389"/>
firewall-cmd --reload
firewall-cmd --permanent --add-service=xrdp
firewall-cmd --reload

Running xfce or any arbitrary DE

On Fedora, for xfce specifically you need to make sure that X clients are told to run xfce. The vnc services will try to start a window manager, but as of the time of this writing xfce is not included in the list, so it will fail out (or run gnome, if it’s present).
The file to inspect is /etc/X11/xinit/Xclients, or the per-user settings at ~/.Xclients. For the etc file, it should be fairly obvious how to add to it. Additionally, make sure the file is executable!

For Fedora 26 and xfce, you can inspect this patch file, and then either run the patch statement or make the changes yourself manually.

# for all users
tf=/etc/X11/xinit/Xclients.patch; touch "${tf}"; chmod 0644 "${tf}";
cat <<'EOFPATCH' >"${tf}"
--- /etc/X11/xinit/Xclients	2017-02-12 00:38:18.000000000 -0500
+++ /etc/X11/xinit/	2017-10-14 08:12:34.340524791 -0400
@@ -12,6 +12,7 @@
 MSESSION="$(type -p mate-session)"
 STARTKDE="$(type -p startkde)"
 STARTLXDE="$(type -p startlxde)"
+STARTXFCE="$(type -p startxfce4)"
 # check to see if the user has a preferred desktop
@@ -25,6 +26,8 @@
     elif [ "$DESKTOP" = "LXDE" ]; then
+    elif [ "$DESKTOP" = "XFCE" ]; then
@@ -44,6 +47,9 @@
 elif [ -n "$STARTLXDE" ]; then
     # if neither GNOME nor KDE then LXDE
     exec "$STARTLXDE"
+elif [ -n "$STARTXFCE" ]; then
+    # if none of the above, try XFCE.
+    exec "$STARTXFCE"
 # We should also support /etc/X11/xinit/Xclients.d scripts
patch -p1 /etc/X11/xinit/Xclients < /etc/X11/xinit/Xclients.patch

And for the individual users (I have yet to test to see if the normal order of resolution of the X files lets this actually override it for the user):

tf=~/.Xclients; touch "${tf}"; chmod 0700 "${tf}";
cat <<EOF > "${tf}"
exec /usr/bin/startxfce4

And that’s it! A sample xfreerdp statement to connect to this service could be:

xfreerdp /sec-rdp /cert-tofu /size:1520x820 /bpp:16 /v: -z /disp /audio-mode:0 /wallpaper /themes /u:bgstack15
Screenshot of session manager login screen in vnc in xrdp
Login screen after connecting to xrdp service



  1. Using the patch utility
  2. update file /etc/X11/xinit/Xclients
  4. General xrdp guide
  5. Notes about cinnamon on CentOS 7
  6. xrdp on centos 7

Cinnamon on VNC on CentOS 7


This document describes how to install Cinnamon desktop environment on CentOS 7 for use in VNC. Basically, you can take a headless server and turn it into a virtual desktop controller.


Limitations of this design prevent this from scaling up past so many users, so this would be best suited for home or small office use.
VNC uses no security. Consider alternatives or additions to this process when security is a consideration.

Installing Cinnamon for VNC

Installing the components

Install the vnc server.

yum install tigervnc-server tigervnc vnc

Install the desktop environment.

yum install cinnamon

Install any applications to be used.

yum install firefox gnome-terminal

Configuring the components

For each user that uses a virtual desktop on this host, you will need a separate systemd service, as well as a vnc password which is separate from the regular user password. Also set up the xstartup file for vnc.

sudo cp -p /lib/systemd/system/vncserver@.service /etc/systemd/system/vncserver@\:${tn}.service
sed -r -i -e "s//${tu}/g;' /etc/systemd/system/vncserver@\:${tn}.service
systemctl enable vncserver@\:${tn}.service
firewall-cmd --permanent --add-port 59$( printf '%02i' "${tn}")/tcp
printf "For user ${tu} please provide new "
su - ${tu} -c vncpasswd
test -f "${tf}" && \cp -p "${tf}" "${tf}.$( date "+%Y-%m-%dT%H%M%S" )"; touch "${tf}"; chmod 0755 "${tf}"
cat <<EOF > "${tf}"
[ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup
[ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources
exec /usr/bin/cinnamon-session
systemctl start vncserver@\:${tn}.service

Connecting to the desktop

On a client, run

vncviewer hostname:1