How to REALLY fix Chrome Remote Desktop on Ubuntu 18.04

So, as I hinted in my last post, I’ve been fixing up an Ubuntu machine to do some development on.  This machine needs to be headless because it isn’t my primary development machine, and running a VM everywhere I have a Mac has become incredibly painful and slow … especially with having to keep them all up to date.

The first problem here is that basically every free remote desktop solution I’ve tried is ALSO incredibly slow and painful.  Except for Chrome Remote Desktop, which is doing something reasonably smart and encoding the screen with VP8 to send to the remote client.

However, the problem with Chrome Remote Desktop is that it’s configured by default to login on a completely separate X desktop from the logged in user.  Which … I don’t know, maybe I could get that to work, but also it makes it really weird when I’m trying to troubleshoot back and forth on the computer directly vs a headless login.

I found a post titled “How to Install Chrome Remote Desktop on Ubuntu 18.04” and it really seemed like it was going to fix all of the above by modifying the startup script to point at the logged in display number.  Sadly, it really didn’t end up doing that at all.  But at least pointed me in the right direction!

What the aforementioned script does is tell you to look at your current X display number and just hardcode that into the script.  This ends up not working at all, because in my experience, the logged in display number isn’t a constant thing, even if you enable auto login.  So the script just ends up failing with nonsense that you have to dig out of the logs.  In fact, it’s sort of worse that not working because it appears to work at first when you try it out for the first time, but as soon as you reboot you might just lose access to your machine completely when you need it the most.

The solution to this I came up with was to A. auto login my user and B. modify the script to wait for the logged in user and retrieve the actual display number before continuing.

There are, of course, caveats with this whole approach that could use additional hardening, but it’s “good enough” for what I need to do, so I’ll just leave it at that.

So, in addition to the script modifications in the above linked post, look for where FIRST_X_DISPLAY_NUMBER is hardcoded in the script. Instead of replacing it with a hardcoded number, use the following code:

FIRST_X_DISPLAY_NUMBER = None
for x in range(0,10):
    if x > 0:
        time.sleep(10)
    W_OUTPUT = subprocess.check_output("w")
    print("W_OUTPUT: {0}".format(W_OUTPUT))
    W_OUTPUT_LINES = W_OUTPUT.splitlines()
    if len(W_OUTPUT_LINES) < 3:
        continue

    FIRST_USER = W_OUTPUT_LINES[2]
    print("FIRST_USER: {0}".format(FIRST_USER))
    FIRST_X_DISPLAY_NUMBER = FIRST_USER.split()[2]
    print("FIRST 1: {0}".format(FIRST_X_DISPLAY_NUMBER))
    if FIRST_X_DISPLAY_NUMBER is None:
        continue

    FIRST_X_DISPLAY_NUMBER = FIRST_X_DISPLAY_NUMBER.strip(":")
    print("FIRST 2: {0}".format(FIRST_X_DISPLAY_NUMBER))
    FIRST_X_DISPLAY_NUMBER = int(FIRST_X_DISPLAY_NUMBER)
    print("FIRST 3: {0}".format(FIRST_X_DISPLAY_NUMBER))
    break

And voila!  Chrome Remote Desktop will start on whatever X display the logged in user is on.

This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s