You have many options when it comes to which VNC server and desktop environment you choose. In this tutorial, you will install packages for the latest Xfce desktop environment and the TightVNC package available from the official Ubuntu repository. Both Xfce and TightVNC are known for being lightweight and fast, which will help ensure that the VNC connection will be smooth and stable even on slower internet connections.
After connecting to your server with SSH, update your list of packages:
Now install the Xfce desktop environment, along with the xfce4-goodies
package, on your server:
During installation, you may be prompted to choose a default display manager for Xfce. A display manager is a program that allows you to select and log in to a desktop environment through a graphical interface. You’ll only be using Xfce when you connect with a VNC client, and in these Xfce sessions you’ll already be logged in as your non-root Debian user. So for the purposes of this tutorial, your choice of display manager isn’t pertinent. Select either one and press ENTER
.
Once the installation completes, install the TightVNC server:
Next, install the dbus-x11
dependency to ensure a proper connection to your VNC server:
To complete the VNC server’s initial configuration after installation, use the vncserver
command to set up a secure password and create the initial configuration files:
Next there will be a prompt to enter and verify a password to access your machine remotely:
Output
You will require a password to access your desktops.
Password:
Verify:
The password must be between six and eight characters long. Passwords with more than eight characters will be truncated automatically.
Once you verify the password, you have the option to create a view-only password. Users who log in with the view-only password will not be able to control the VNC instance with their mouse or keyboard. This is a helpful option if you want to demonstrate something to other people using your VNC server, but this isn’t required.
The process then creates the necessary default configuration files and connection information for the server:
Output
Would you like to enter a view-only password (y/n)? n
xauth: file /home/sammy/.Xauthority does not exist
New 'X' desktop is your_hostname:1
Creating default startup script /home/sammy/.vnc/xstartup
Starting applications specified in /home/sammy/.vnc/xstartup
Log file is /home/sammy/.vnc/your_hostname:1.log
Next, configure it to launch Xfce and give access to the server through a graphical interface.
The VNC server needs to know what commands to execute when it starts up. Specifically, VNC needs to know which graphical desktop it should connect to.
These commands are located in a configuration file called xstartup
in the .vnc
folder under your home directory. The startup script was created when you ran the vncserver
command in the previous step, but you’ll create your own to launch the Xfce desktop.
When VNC is first set up, it launches a default server instance on port 5901
. This port is called a display port, and is referred to by VNC as :1
. VNC can launch multiple instances on other display ports, like :2
, :3
, and so on.
Because you are going to change how the VNC server is configured, first stop the VNC server instance that is running on port 5901
with the following command:
The following is the output with a PID specific to your server environment:
Output
Killing Xtightvnc process ID 17648
Before you modify the xstartup
file, back up the original:
Now create a new xstartup
file and open it in your preferred text editor:
Commands in this file are executed automatically whenever you start or restart the VNC server. You need VNC to start your desktop environment if it’s not already started. Add the following commands to the file:
~/.vnc/xstartup
#!/bin/sh
unset SESSION_MANAGER
unset DBUS_SESSION_BUS_ADDRESS
startxfce4 &
Here is a brief overview of what each line is doing:
#!/bin/bash
: The first line is a shebang. In executable plain-text files on *nix platforms, a shebang tells the system what interpreter to pass that file to for execution. In this case, you’re passing the file to the Bash interpreter. This will allow each successive line to be executed as commands, in order.
xrdb $HOME/.Xresources
: This command tells VNC’s GUI framework to read the user’s .Xresources
file. .Xresources
is where a user can make changes to certain settings for the graphical desktop, like terminal colors, cursor themes, and font rendering.
startxfce4 &
: This command tells the server to launch Xfce. This is where you will find all the graphical software that you need to comfortably manage your server.
When you’re finished, save and exit out of your editor. If you’re using nano
, you do so by pressing CTRL+X
, then Y
, then ENTER
.
To ensure that the VNC server will be able to use this new startup file properly, you need to make it executable:
Now, restart the VNC server:
The output will be similar to the following:
Output
New 'X' desktop is your_hostname:1
Starting applications specified in /home/sammy/.vnc/xstartup
Log file is /home/sammy/.vnc/your_hostname:1.log
With the configuration in place, you’re ready to connect to the VNC server from your local machine.