One major problem with using XRDP – the remote desktop service for linux servers, has been the issue of not being able to connect to the same session again. It actually opens up another session, barring you from entering the previous session where you left some work. This creates a lot of problems. And this issue is very much there atleast on ubuntu systems.

I have however been able to fix it. And here’s how it works. Assuming you already have a working xrdp with xfce4 on ubuntu:

 

Connect to the server using mstsc client on windows

open run prompt in windows and type mstsc

Once you have the window, enter the ip and click on advanced

Choose options as shown in below images (these are actually for better performance)

snip1

snip2

Then once connected, enter your username and password to login to the remote linux system

Now in the remotely connected linux environment, open up a terminal and type

netstat -tulpn | grep vnc

This will give you the vnc port to which your current session is connected to

tcp        0      0 127.0.0.1:5911          0.0.0.0:*               LISTEN      23357/Xvnc

This 5911 (or 5910 or 5912 or something similar) is your current session number

Then you have to tell xrdp to always let you choose the port while connecting

That you can achieve with the following command

vi /etc/xrdp/xrdp.ini

And then by changing line number 25 to

port=ask

At end, the file would be like

[globals]
bitmap_cache=yes
bitmap_compression=yes
port=3389
crypt_level=low
channel_code=1
max_bpp=24
#black=000000
#grey=d6d3ce
#dark_grey=808080
#blue=08246b
#dark_blue=08246b
#white=ffffff
#red=ff0000
#green=00ff00
#background=626c72

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

[xrdp2]
name=console
lib=libvnc.so
ip=127.0.0.1
port=5900
username=na
password=ask

[xrdp3]
name=vnc-any
lib=libvnc.so
ip=ask
port=ask5900
username=na
password=ask

[xrdp4]
name=sesman-any
lib=libvnc.so
ip=ask
port=-1
username=ask
password=ask

[xrdp5]
name=rdp-any
lib=librdp.so
ip=ask
port=ask3389

[xrdp6]
name=freerdp-any
lib=libxrdpfreerdp1.so
ip=ask
port=ask3389
username=ask
password=ask

[xrdp7]
name=sesman-X11rdp
lib=libxup.so
username=ask
password=ask
ip=127.0.0.1
port=-1
xserverbpp=24

Then save the file. And then disconnect your session

Next time when you connect, you will get an extra field to put your port number in it. If your previous session port number was 5911 then put that there and voila! – you will be connected to your previous session.

snip3