How to set up Linux desktop environment in the cloud with DigitalOcean droplet

Oleksii Chekulaiev
3 min readDec 4, 2017

--

The easiest and the most cross-platform option to get “desktop in the cloud” is to install a VNC server onto the DigitalOcean box. There is a comprehensive instruction from D.O. how to do that: how to install and configure VNC on Ubuntu. It was written for Ubuntu 16.04, but I used them for Ubuntu 17.10 and they worked fine. However there are additional steps that I needed to perform and that’s what brought this short guide to life.

Once you have created an Ubuntu 17.10 droplet and logged in via ssh as root, your sequence of actions is following:

# 1. Installing XFCE and VNC server
apt update
apt install xfce4 xfce4-goodies tightvncserver
# 1.1. If you're on vultr.com you will need more packages
apt install xfonts-base x11-xserver-utils
# 2. Initial VNC server config# Prompts to set up password for VNC server here...
vncserver
# Allow clients to connect to X server from any host
# inspired by https://superuser.com/a/392263/140872
DISPLAY=:1 xhost +
# 3. Now creating proper config and restarting the server
vncserver -kill :1
mv ~/.vnc/xstartup ~/.vnc/xstartup.bakcat << EOF > ~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
EOF
chmod +x ~/.vnc/xstartup# 4. Creating a user accountexport USERNAME="username" # Replace with desired user nameuseradd --create-home $USERNAME
adduser $USERNAME sudo
passwd $USERNAME
# Copy ssh keys to new user
mkdir -p /home/$USERNAME/.ssh
cp ~/.ssh/authorized_keys /home/$USERNAME/.ssh/
chown -R $USERNAME:$USERNAME /home/$USERNAME/.ssh
# Copy VNC settings to a new user
mkdir -p /home/$USERNAME/.vnc
cp ~/.vnc/xstartup /home/$USERNAME/.vnc/
chown -R $USERNAME:$USERNAME /home/$USERNAME/.vnc/
# 5. Start VNC server# Stop command. Just in case. Ignore errors here
su $USERNAME -c "vncserver -kill :1"
# Start
su $USERNAME -c "vncserver -depth 24 -geometry 1280x800"
# 6. How to stop VNC server when you are done?
# su $USERNAME -c "vncserver -kill :1"

Now at this moment you should have a VNC server running with your non-root account and waiting for you to connect.

If you’re on macOS, then you already have a VNC client and it is called “Screen Sharing” (NOTE: in macOS 10.13 it is now called “Screen Share” and does not longer support connecting to tightvnc). Just start it and connect to your_server_ip:5901. It will ask for password to VNC server, the one you set up in step #2.

Upon entering your password you should see your new and shiny Linux cloud desktop environment.

Continue with setting up XFCE per your needs

The instructions on DigitalOcean also walk you through service creation, but I was not able to make TightVNC to work properly when launched as a service. That’s why I used a different automation. To allow for quick VNC server start and stop, I created 2 scripts on my DigitalOcean droplet.

/usr/local/bin/vncstop#!/bin/bash
su username -c "vncserver -kill :1"

Don’t forget to put the real user name instead of username.

/usr/local/bin/vncstart#!/bin/bash
vncstop
su username -c "vncserver -depth 24 -geometry 1280x800"

I have also added my droplet’s IP to the local /etc/hosts file on macOS:

111.111.111.111 vnc

Now when I need my VNC server, I run ssh root@vnc vncstart and then I can connect with Screen Sharing. Once finished I usually stop VNC server with ssh root@vnc vncstop.

--

--

Oleksii Chekulaiev
Oleksii Chekulaiev

Written by Oleksii Chekulaiev

Drupal Technical Lead, Docksal creator and maintainer

Responses (2)