- 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.
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 user@IP-ADDRESS
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.
$ sudo touch /dev/fuse $ sudo apt install xfce4 xfce4-goodies gnome-icon-theme
$ 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:
The remote desktop will appear directly on your own.
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:
- Vinagre [Linux]
- Real VNC [Windows/OS X/Linux/iOS/Android]
- TightVNC [Windows/OS X/Linux]
- TigerVNC [Linux/Windows/OS X]
Connect to your VNC server by appending :1 to the IP address of your VPS. You’ll have access to the full desktop!
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.