XRDP- How to Start Unity Automatically in Ubuntu 17.04

Hello world, 

Today, we are back with a short post about XRDP and Unity Desktop in Ubuntu 17.04. Installing xrdp in Ubuntu 17.04 is really easy and there is no major configuration changes that’s needed in order to have it working.  However, there is one small limitation that kind of annoying if you are not a technical user.  This limitation is the fact that the Unity Desktop is not loading automatically when performing your remote desktop connection.  The user will need to start the Unity Desktop inside the remote desktop session….and this is not cool…. 

In this post, we will provide a possible strategy that can be used in order to have the Unity Desktop loaded automatically when the user connect to the Ubuntu machine through remote Desktop session. 

Let’s do this….. 

Overview

In one of our previous post, we have demonstrated how to install xrdp package software on a Ubuntu 17.04 machine.  The process is quite straightforward nowadays. Nowadays, you simply needs to install the xrdp package from Ubuntu repository in order to have a working remote desktop solution.  The xrdp package shipped with Ubuntu 17.04 is the version 0.9.1.xx which offers out of the box drive redirection and clipboard capabilities.  It also offer the new xorgxrdp backend component aimed to replace the vnc server that was used in previous versions… 

A lot of improvements have been made in the latest iteration of xrdp package and Ubuntu latest release. It now easier to install and use xrdp software against Linux machine. However, there are still some small issues that exist.  One of them is when you are using Unity Desktop Interface in Ubuntu 17.04.  

In the post XRDP – How to install XRDP on Ubuntu 17.04 – Easy Way, one of the limitation or drawback of using Unity and xrdp was that the Unity Desktop interface needed to be started manually.  In other words, the first time you connect to your Ubuntu machine using xRDP, you will get a black screen.  If you right click on the black screen and start the terminal session, you will be able to issue the necessary command to start Unity…. These actions will load the Unity Desktop at the end but we have been looking for better ways to perform the same actions in an automated way…. 

The Old Way 

In previous versions of xrdp and/or Ubuntu, we could use the file .xsession or /etc/xrdp/startwm.sh to have the desktop interface loaded automatically.  In Ubuntu 17.04, it’s not the case anymore.  In our case, each time we have populated the .xsession file with the Unity desktop instructions, a remote connection was performed which was immediately dropped….  

So, this approach seems to be broken in Ubuntu 17.04 (with Unity Desktop)

We needed to came up with another solution….. 

The Alternate Way 

In the post XRDP – How to install XRDP on Ubuntu 17.04 – Easy Way,  a workaround has been mentioned in order to load automatically the Unity Desktop.   The alternate way is basically a way to execute a script at startup when the user logs in. Luckily for us,  Ubuntu ships with a small tool that can done exactly that.  The name of the tool is Startup Applications.

If you are logged locally on your Ubuntu machine, launch the Dash and type the following Startup Applications.  You should see the following icon.  Click on it

U1704_xrdp_14

Click on picture for better resolution

If everything is OK, you should see the startup application windows displayed in front of you.  You have now the possibility to add the application (or script) you would like to have loaded when the user logs in…. Press Add button and provide the requested information. 

U1704_xrdp_15

Click on picture for better resolution

The most important part here is the command textbox.  In this textbox, you will need to specify the script you would like to have started at startup. 

The Script to load Unity Automatically 🙂

It’s time for us to share an extract of our startup script that we used to load automatically the Unity Desktop.  The script provided is really basic but should provide the necessary actions needed to have Unity loaded automatically. 

Initially, we thought that creating a startup-unity.sh file, make it executable and populating with the simple command like 

exec unity

would have been enough….  but this is not enough….we could do better.  

What we need to do in our script is to simply detect the Display we are connected to.  if the Display is :0 we are logged on locally. However, if the display is :10 then, we are probably using the Remote Desktop Connection.

So, the following commands could be used 

## Get the display value for the session...
test=$(echo $DISPLAY)

if [ $test = ":10.0" ] 
then
   ## Connected through Remote Desktop so load Unity Desktop  
   exec unity
else 
   ## Do not execute anything this is local connection
fi 

The script above assume that basically only one user would connect to the remote session and the display that will be used would be :10.  However, in real life, this is not necessarily the case. If you have more users or that for any other reasons the display number has changed from :10 to :11 or :12….the startup script is not working anymore…. 

So, the workaround would be to look for something that’s different that :0 instead of looking of specifically for display :10.  So, a possible better script would be to perform a check like this

## Get the display value for the session...
test=$(echo $DISPLAY)

if [ $test != ":0" ]
then
   ## Connected through Remote Desktop so load Unity Desktop  
   exec unity
else 
   ## Do not execute anything this might be local connection
fi

This script should cover most of the scenarios….. 

Final Notes

And voila !  Now, using this alternate approach you should be able to have Unity Desktop loaded automatically while performing your remote desktop connection through xrdp package.  Between each releases of Ubuntu and xrdp, it seems that improvements are made available.  On the other hands, some of the features breaks between releases… This is becoming frustrating…..

So, yes it’s possible to use xrdp against Ubuntu 17.04 but you still need to create a startup script to have the Unity Desktop loaded automatically. In the past, we could use the .xsession file or the /etc/xrdp/startwm.sh.  These approaches does not seems to work anymore.  We had to come up with an new way of doing things.  The startup script seems to be a pretty good approach…Using this approach and performing a standard xrdp installation process (while taking into account all the limitations of the solutions), you should be able to remote desktop directly into your Unity Desktop via remote sessions… 

Hope this post can be useful to anybody…

Till next time…

See ya  

 

 

9 thoughts on “XRDP- How to Start Unity Automatically in Ubuntu 17.04

  1. Hi Griffon,
    Thanks for taking time and writing this useful stuff. I’m on Ubuntu 17.04 and have xrdp installed as you suggested. My .xsession file has unity and I also have the script you mentioned in this post. Even after this, I sometimes get my session getting closed or staying active. The active session does not do anything for right click. This is very frustrating. What else can you suggest me?
    Thanks in advance.

  2. hello,
    my remote desktop session quits when i execute “exec unity” command on terminal. any help please?

  3. hi,

    Thank you for setting up this informative blog. Its a good resource for ubuntu beginners like me.

    I created the script as instructed but it works for the first login only. If I Logout from the first rdp session and try to login remotely (rdp) for the second time, the script doesnt launch unity desktop. I have to start terminal and run exec unity to launch unity desktop again.

    if i close the rdp session without logging out, it works fine.

    could you please help…. need to run script for every xrdp session.

    current setup – virtual box on windows 8.1 , running 17.04 ubuntu.

  4. Hi,

    Just wanted to update my earlier post regarding the script working for the first time and not working after logout.

    it seems if you logout and login again immediately then there is problem loading the unity desktop. if you wait 60 seconds or more and then login again it loads unity desktop.

    after logging in you need to wait 60 seconds or more before logging out so that there are no issue when launching unity desktop.

    is there anyway to ensure that when user logs out it logs out after one minute and to ensure when he logs in he logs in after one minute.

    thanks

  5. @Mesh,

    Sorry it didn’t work for you… We have no more suggestions so far… xrdp is still not the perfect solution but covers our needs so far. We have tested the described procedure many times and we are currently using it on a daily base and we do not have that many issues or issues that could be compared to yours…. We will try to have a look into the issue and try to reproduce the error but no guarantee

    Till next time
    See ya

  6. @Faiz,

    No clue so far… You do not provide any info about your setup and actions you have performed…. have you checked your logs to try to isolate the issue ?

    Till next time
    See ya

  7. @MZF,
    Thank you for the feedback and comments about this topic… We never noticed that it would take 60 sec before a user could login…Actually, we have tried and we do not have the issue….
    To meet your requirements, you could try to adapt scripts or create your own script to introduce the 60 sec delay…

    Hope this help
    Till next time
    See ya

Leave a Reply