VNC on VPS Programming Workspace Tutorial – Part 1

I recently put together a VNC programming workspace on my VPS server, and so far, I’m loving it! It’s seriously the best thing ever for cloud programming. I can program where ever, and whenever I want. All of my files are “just there”. It’s amazing! I can even program on my phone or tablet if I want. At the end, I’ll show you how to setup an html5 vnc viewer so you can program in your browser. In this first section, I’ll teach you how to get a VNC server running on your VPS. This tutorial assumes that you already have a blank VPS running Ubuntu Server 14.04. This may work on a few other Linux OS’ but I have not tested on them. In part two, I’ll show you how to set up Eclipse, and a nice HTML5 client to go along with this.

The first thing you’ll need to do, if you haven’t already, is get a VPS. I got mine through a service called OwnageHosting. For only about $10 a month, I can get a 5gb server. I’ve also installed Ubuntu Server 14.04 on it, so that’s what I’ll be using for this tutorial. If you’d like to follow along, I’d recommend you do the same. Once you have a VPS with Ubuntu 14.04, log into your server through SSH as root, and meet me back here.

We’ll start by creating a new user called “vnc”.

Go ahead and enter a password for it, and then press enter a few times to just skip over the prompts. Then, simply type “y” to confirm your information. Next, we’ll give the account root privileges.

Next, go ahead and SSH into your new user. Now, we must install a desktop environment, as well as a VNC server. We’ll being using XFCE4 as our desktop environment, and TightVNC as our VNC server. We’ll also install a text editor called nano. If you’d prefer to use your own text editor,  After updating our repositories, we can simply install everything with a single command.

You’ll have to confirm your installation on the second command, and then everything will start downloading and installing. After all is done, we can configure the VNC client using the following command.

You can now enter an access password. This is the password that you’ll use to connect to your desktop and control it. If you’d like to allow others to view your desktop but not control it, you can also set a “view-only” password. After configuring a password for your VNC server, we need to modify our xstartup file. The file will allow us to run commands before our VNC server starts. Before we edit our xstartup file, we must first shutdown our VNC server. We can do this with the following command.

TightVNC comes with a xstartup file already, but we’re going to need to modify it to get it work with xfce4. Just in case we need to revert back to the “stock” xstartup file, let’s go ahead and back it up with the following command.

Now we’re finally ready to create a new xstartup file. If you’re doing nano, we can do that with the following command.

This will open up a blank xstartup file for us. Just go ahead and start by typing the following, and then I’ll explain it line-by-line so you know what we’re doing.

The first line is just telling Linux that we’re using bash. Our .xstartup file is actually just a bash file. The next line loads our settings for xfce4, and the third and final line will start xfce4.

Now, we just need to set that file as an executable so that it can be run by TightVNC. We can do this with the following command.

We’re getting close to being done with getting VNC set up. We’re just going to set it up as an Ubuntu service. This will allow us to have easy control over starting, stopping, and restarting our VNC server. To do this, we’ll start by creating a new service file for our vncserver like so.

The code that we’ll be using for the startup file is a little bit long. If you don’t feel like typing it all by hand, you can download it using the second command below.

We will also need to make the file executable so that we can run it. We can do so with the following command.

The startup file that we’re using, uses a config file that we must now create. This allows us to change our vnc user, or our desktop resolution easily. We need to first create the proper directory, and then create/edit the configuration file. We can do so using the following two commands.

Now, simply type in the following to create a simple vnc config file. I’ll explain the options later.

The first line defines our port, and our vnc username. VNC binds to poit 590x. x is the first bit on that line. In our case, it’s just “1”. This means that our server will be run on port 5901. The second little bit is our VNC username. In our case, it’s just “vnc”. The second line defines our screen size. In our case, we’ll be using “1024×768”. I’d recommend setting this to the aspect ratio of the monitor you’ll be using the most.

We’re almost done with the VNC bit. Now, we’ll make our VNC server start when our VPS starts up, with the following command.

Now all that’s left to do is reboot.

That should do it for setting up our VNC server! Once your VPS finishes rebooting, you should be able to use any VNC client to log into your VPS’ virtual desktop. I like to use Tight VNC’s Java viewer. It’s portable, and multi-platform which is nice. You can keep it on a thumb drive, and use it no matter which OS you’re on. If you’re interested, you can get a direct link HERE. Once you open the jar, just type in your VPS’ IP and port. If you followed along with my config, your port should be 5901.

Leave a Reply

Your email address will not be published. Required fields are marked *