• You Jun

Khadas Blog | How To Install VNC Server On Ubuntu Mate

Updated: Mar 9, 2020

Remote control your Khadas VIM from a smartphone or PC, without a monitor!

Khadas VIM’s Remote Desktop, as seen through Remmina (Ubuntu 16.04)

0. Why Install VNC Into Your Khadas VIM SBC?

In many instances, you may not have or want an external monitor connected to your Khadas VIM. Or you may have a need to connect to your VIM remotely, but still want a Graphical User Interface (GUI), instead of just an SSH shell. This is when a VNC server comes in handy!

Headless Khadas VIM2 (no monitor), running via USB PowerBank (5v, 2.1A)

Using VNC, you can also connect to your Khadas VIM via your smartphone to impress your friends!

Remote controlled VIM, from my iPhoneX, using the RealVNC app.

1. Ensure You Have Ubuntu Installed In Your Khadas VIM SBC

This guide will assume that you’ve already installed Ubuntu Mate into your Khadas VIM, using the Android-Ubuntu Dual-Boot image found here. If you have not installed Ubuntu yet, check out my other guide, “How to Install Ubuntu Into Khadas VIM”.

Dual Boot EMMC Image:

2. Get Ethernet Or Wi-Fi Working On Khadas VIM

The next step is to get the Ethernet or Wi-Fi to work, we need this because we will need to use the SSH shell to install the VNC server. You have 2 options:

Method 1 — The easier method, is to just plug in an external monitor via HDMI cable, so that you can use a keyboard and mouse to connect to your home Wi-FI.

The Khadas VIM has a variety of rear ports, it’s a mini computer! Connect a monitor, keyboard and mouse, via HDMI and USB, or a LAN cable via the Ethernet port. USB-C is used for the 5V, 2.1A power supply.

Method 2 — The not so easy method, is to plug an Ethernet cable into your VIM, and then use a LAN scanner like the Fing app, to find it on your LAN.

Finding your Khadas VIM via the Fing app, isn’t that easy. It will be classified as a generic device, and should have SSH on port 22 opened.

What do I use? I wrote a little startup bash script, that sends me a Telegram notification every time my Khadas VIM boots up. That’s another story for yet another guide.

My Khadas VIM sends a notification to Telegram containing it’s IP address upon boot up.

3. Logging Into Khadas VIM Using SSH

Once you’ve found the IP-address of your Khadas VIM, simply open Terminal on your Mac to use SSH to login to it. For Windows users, you will need to download Putty. By default, both the username and password are khadas.

Username: khadas Password: khadas
Using SSH via the Mac OS X Terminal app.
$ ssh khadas@x.x.x.x $ khadas@x.x.x.x's password: khadas

x.x.x.x = your Khadas VIM’s IP address.

4. Update Your Khadas VIM’s Ubuntu Mate OS

This step may seem weird and unfamiliar to people who are not acquainted with Linux. Although Linux doesn’t have a GUI updater, updating is done easily via the terminal.

Before installing new software, always update your Khadas VIM.
$ sudo apt-get update && sudo apt-get upgrade

5. Install The VNC4Server Into Your Khadas VIM’s Ubuntu Mate OS

This step is the easiest, simply respond yes to any questions that arise, and the process will complete itself automatically.

In my case, the VNC4Server is already installed.
$ sudo apt-get install vnc4server

6. Startup The VNC4Server, Then Kill It

We need to start the VNC server so that we can figure out where it’s configuration files are stored. After that we need to kill it, so that we can modify the configuration file.

The command you need to know is vncserver <argument> <port>.
$ vncserver :1 $ vncserver -kill :1

Let’s explain some things for the beginners, vncserver is the shell command to launch a new VNC daemon in Ubuntu Mate. -kill is the <argument> used when you need to kill the daemon. Finally, :1 is the network <port> on which you want to run the daemon on.

For example, if you want to run two VNC daemons simultaneously, type vnc server :1 && vncserver :2 into the terminal. You can then connect to them on ports 5901 and 5902 respectively. If you need to kill them both, type vncserver -kill :1 && vncserver -kill :2.

&& is just the command used when you want to run two shell commands on the same line.

7. Edit your VNC4Server’s Configuration File

Now we need to edit your config file so that when you login to your Khadas VIM via VNC, it will start up the graphical user interface. By default it does not!

You can find the configuration file’s directory, when you previously issued the command vncserver :1. You will find it on the line that says “Starting applications specified in …”.

You can find your configuration file, on the line that says “Starting applications specified in …”

Now that you know where the configuration file is…you can then issue the command to edit the configuration file. sudo is the command given to execute your command as root. If you do not have sufficient privileges to do something, just add sudo in front.

$ sudo nano /home/khadas/.vnc/xstartup

Add the line “mate-session” to the end of your VNC4Server configuration file.
...move the cursor to the bottom of the file, using the arrow keys on your keyboard, then type in... mate-session
Then press Control-X on your keyboard, then press y, then press enter! the following keys on your keyboard... [ Control-X ] [ y ] [ Enter ]

If you did all the above correctly, and in the correct sequence, you would have saved your configuration file with the line mate-session at the bottom! mate-session is the command for starting up Ubuntu Mate’s graphical user interface (GUI).

8. Ensure Your VNC4Server Starts On Ubuntu Mate Boot Up

This step is very important, if you don’t do this, you will not be able to reconnect to your Khadas VIM via VNC if it is rebooted, or loses power.

Use crontab to add the VNC server as a service you wish to run on boot
$ crontab -e

Then add the line @reboot /usr/bin/vncserver :1 to the end of the file.
...move the cursor to the bottom of the file, using the arrow keys on your keyboard, then type in... @reboot /usr/bin/vncserver :1

You can also add additional VNC daemons to run on startup by adding additional lines such as:

...this step is OPTIONAL... @reboot /usr/bin/vncserver :2 #port 5902 @reboot /usr/bin/vncserver :3 #port 5903

Once you’re done, use your keyboard to exit the text editor.

Press Control-X on your keyboard, then press y, then press enter! the following keys on your keyboard... [ Control-X ] [ y ] [ Enter ]

9. Start the VNC4Server Daemon

Type vncserver :1 to start the VNC4 server.
$ vncserver :1

You can check if the server is listening on port 5901 by using netstat. You should see a TCP6 Protocol, running on port 5901. That port should be in a LISTEN state, which means that it is listening for inbound connections.

As you can see above, port 5901 is in a LISTEN state, which means our VNC4Server daemon is running.
...this step is OPTIONAL... $ netstat -a

10. Connect To Your Khadas VIM By VNC Client

This is the fun part that we’ve all been waiting for…actually connecting to our Khadas VIM via VNC, so we get the full desktop experience! First you’ll need to download the RealVNC Client.

Download the RealVNC Client from Mac OS X, or Windows.

If you’re on iOS, you can also download their iOS app.

Download the RealVNC App for iOS.

On your Mac, run the RealVNC app, and type in your VIM’s ip-address, followed by the port that your VNC daemon is running on. In my case it’s

Open the RealVNC Client on your Mac and type in <vim’s ip address>:1.
...inside the RealVNC desktop app... x.x.x.x:1

If your VNC daemon is running on another port such as 5902, then type:

...change the number, depending on the port you chose... x.x.x.x:2

Then enter khadas as the password.
Password: khadas

Tada, you’re done! If you’ve got this far, you’re a genius!

You’ve done it! You’re a genius!

Khadas Products Used In This Post:

Minimally, you’ll need the VIM2 Pro. If you want the DIY Case, then get the Heat Sink too. HDMI, USB-C cables, and the metal plate are optional.

Links To Other Articles (in progress):

4,757 views1 comment