Remote Linux desktop on your VPS with SSH and VNC

Remote Linux desktop on your VPS with SSH and VNC

While you usually connect to your VPS via a terminal, you can also connect to a remote Linux desktop via SSH or VNC to run desktop GUI apps.

There are a number of ways to get this done, from running single commands via X11 forwarding and ssh, to forwarding an entire desktop, to using VNC. In this tutorial, we’ll cover how to do each of these so that you can choose the application that works best for your needs.

Note: We can’t guarantee these operations will be particularly fast—primarily due to latency between your machine and your VPS—but it could come in handy every once in awhile.

Prerequisites

  • A VPS running any of our available OS options.
  • A non-root user account (commands requiring escalated privileges will use sudo).
  • A local machine running Linux, an OS X machine with XQuartz installed, or a Windows machine with Xming installed—this tutorial depends on having some type of X server running locally.
    • Windows users should install Xming.
    • OS X users should install XQuartz.
    • Once Xming/XQuartz are installed, you can then launch an xterm or other terminal to ssh into your VPS and enable X11 tunneling.

FREE VPS BACKUPS FOR LIFE! (Cyber Monday Insanity Hour!)

We’re giving away FREE automated backups for the life with the purchase of any Performance VPS plan with NVMe today only, from 9am to 10am PST.

And we’ve got our best prices ever on HUGE resource cloud hosting plans, like:

Score a 24GB Performance VPS with 240GB of SSD storage for just $99/year!

Get the Cyber Monday deals now!⚡

Forwarding single X applications

To forward a remote Linux desktop running on your VPS, which allows you to view X applications on your local machine, you should connect via ssh using the -X option, which enables X forwarding, and the -C option, which enables data compression.

$ ssh -XC [email protected]

Once into the VPS, you should first install the xauth package.

$ sudo apt install xauth             # Debian/Ubuntu
$ sudo yum install xorg-x11-xauth    # CentOS

Then, open /etc/ssh/sshd_config with your favorite editor and look for the X11Forwarding option. This line should be uncommented and be changed to X11Forwarding yes.

After that, you should restart sshd.

$ sudo systemctl restart sshd

You should then disconnect from your VPS and reconnect. At this point, check to make sure that X11 forwarding is indeed enabled. You should see the following output if it’s working correctly:

$ echo $DISPLAY
localhost:10.0

Let’s install something simple to test out—how about xclock? Once it’s installed, you can run it from the VPS and it will appear on your local machine’s desktop.

$ sudo apt install x11-apps      # Debian/Ubuntu
$ sudo yum install x11-apps      # CentOS
$ xclock

Now you can run just about any X application, from gedit to firefox. Could be particularly useful if you need to install something on your VPS that only has a graphical installer.

Forwarding an entire remote Linux desktop

Running single X applications might be useful every now and then, but what about a full remote Linux desktop? That could go a long way if you need to use GUI applications on your VPS regularly.

For this tutorial, we’ll quickly install the XFCE desktop environment—a good, low-resource choice for this kind of usage—and then forward it via SSH.

Debian/Ubuntu

$ sudo touch /dev/fuse
$ sudo apt install xfce4 xfce4-goodies gnome-icon-theme

CentOS

$ sudo yum install epel-release -y
$ sudo yum groupinstall "X Window system"
$ sudo yum groupinstall xfce

Once XFCE is installed, you can SSH into your VPS (if you’re not already) and begin a new session:

$ xfce4-session

The remote desktop will appear directly on your own.

A remote XFCE session running on my local machine via X11 forwarding
A remote XFCE session running (somewhat ungracefully) on my Fedora/Gnome-based local machine via X11 forwarding

Remote Linux desktops via VNC

VNC is yet another option for those who want to connect to a remote machine and use the full desktop. It’s a little more involved that some of the others, but we’ll walk through the quickest way to get a VNC server up and running.

Before you go ahead with VNC, you should follow the instructions above on installing XFCE or another desktop environment.

First, you need to install a VNC server on your VPS.

$ sudo apt-get install tightvncserver   # Debian/Ubuntu
$ sudo yum install tigervnc-server      # CentOS

Then you can run the server itself. The first time, you’ll be prompted to create a VNC-only password.

$ vncserver :1 -geometry 800x600 -depth 24

You will require a password to access your desktops.

Password:
Verify:
xauth:  file /home/user/.Xauthority does not exist

New 'user:1 (user)' desktop is hostname:1

Creating default startup script /home/user/.vnc/xstartup
Starting applications specified in /home/user/.vnc/xstartup
Log file is /home/user/.vnc/hostname:1.log

Finally, start up your favorite VNC client. A number of options exist depending on your operating system:

Connect to your VNC server by appending :1 to the IP address of your VPS. You’ll have access to the full desktop!

Note: The default VNC server isn’t very secure, and creates another potential attack vector. Be sure to check out the resources below for more information about securing your VNC server.

Further resources

[cta text=”Run a remote desktop for $1.11/mo and get 16GB RAM.” text2=”You’re 90 seconds away from running a remote desktop on SSD Nodes!” button=”Deploy a remote desktop”]