How to install VNC Server on Ubuntu 14.04

I have shown you How to install VNC Server on CentOS 6, today I’m going to show you How to install VNC Server on Ubuntu 14.04 since many people like and use Ubuntu these days. I mostly spend time with Centos but not with Ubuntu. I spent quite sometimes to make VNC Server to work on Ubuntu 14.04 because gnome doesn’t play nice with VNC Server.

Update and Upgrade Ubuntu 14.04

To make sure the installation of VNC Server go smoothly, check your Ubuntu 14.04 is up to date.

1

$su-

1

# apt-get update; apt-get dist-upgrade -y --force-yes

Install GUI on Ubuntu 14.04 Server

If you have Ubuntu 14.04 LTS (Trusty Tahr) Desktop version, you can skip gnome-core and xubuntu-desktop packages, you will only need xfce4. Well we don’t need a GUI on Ubuntu 14.04 over ssh, but for VNC purpose we are going to install a GUI to work with Ubuntu comfortably. There are two options here for you to choose, either gnome-core with xfce4, or xubuntu-desktop with xfce4. I have tried to make gnome to work over VNC but no luck so far. So make your pick.

1

# apt-get install gnome-core xfce4 firefox nano -y --force-yes

Or

1

# apt-get install xubuntu-desktop xfce4 firefox nano -y --force-yes

Install VNC Server on Ubuntu 14.04

It’s quite simple to install VNC server on Ubuntu 14.04, but it’s not that simple to configure VNC server :)

1

# apt-get install vnc4server -y --force-yes

Configure VNC Server to work on Ubuntu 14.04

You can remotely control your Ubuntu 14.04 system via VNC with any user that you want. Some people would recommend you to install and run login to VNC server as root user to avoid sudo escalation privileges which is not a good security practice at all. In this tutorial I will add new user called vncuser you can use any user as you want.

1

# adduser vncuser

set vncuser password

1

# passwd vncuser

Now switch to the user you want to login to VNC server with. We are going to modify xstartup file to start xfce4 session whenever VNC server is started.

1

# su - vncuser

Start VNC server with that user for VNC server to create some necessary files first time.

1

$vncserver

VNC server will ask you for a password you want to use to login to VNC server, this password does not necessary to be the same as regular user password. This is the sample output

1

2

3

4

5

6

7

8

9

10

11

vncuser@namhuy:~$vncserver

You will requireapassword toaccess your desktops.

Password:

Verify:

xauth:file/home/vncuser/.Xauthority does notexist

New'namhuy:1 (vncuser)'desktop isnamhuy:1

Creating defaultstartup script/home/vncuser/.vnc/xstartup

Starting applications specified in/home/vncuser/.vnc/xstartup

Log file is/home/vncuser/.vnc/namhuy:1.log

After VNC Server started and created some of it’s files. We are now can turn it off to modify the xstartup file (startup script) to make it start with xfce4 instead of gnome which doesn’t work right with VNC Server on Ubuntu 14.04.

To kill VNC Server session

1

$vncserver-kill:1

To modify xstartup file (these commands will empty xstartup file, if you installed wine before vnc server and you want to keep the old content of xstartup file, skip this line $ > .vnc/xstartup ) thanks Hamid

1

$cd~

1

$>.vnc/xstartup

1

$nano.vnc/xstartup

With the content

1

2

3

4

5

6

7

8

9

#!/bin/sh

unset SESSION_MANAGER

unset DBUS_SESSION_BUS_ADDRESS

startxfce4&

[-x/etc/vnc/xstartup]&&exec/etc/vnc/xstartup

[-r$HOME/.Xresources]&&xrdb$HOME/.Xresources

xsetroot-solid grey

vncconfig-iconic&

Save xstartup when you are done. The next step is to create VNC Server statup script. You must do this with root user

Save the file. We are almost there, now we are going to create VNC Server configuration file in /etc/ directory

1

# mkdir -p /etc/vncserver

1

# nano /etc/vncserver/vncservers.conf

Copy the content to vncservers.conf file. The first line is for VNC ports and VNC users. number “1” is the VNC port, it’s port “1” or “5901”, you can add or change the port to “2” or “5902” and so on. If you want more users to connect to your VNC Server, you must include those users here. The second line VNCSERVERARGS is to set VNC screen size.

1

2

VNCSERVERS="1:vncuser"

VNCSERVERARGS[1]="-geometry 1024x768"

The final step is to make VNC Server starts on boot

1

# update-rc.d vncserver defaults 99

and the output, you can ignore missing LSB information warning.

1

2

3

4

5

6

7

8

9

10

update-rc.d:warning:/etc/init.d/vncserver missing LSB information

update-rc.d:see

Adding system startup for/etc/init.d/vncserver...

/etc/rc0.d/K99vncserver->../init.d/vncserver

/etc/rc1.d/K99vncserver->../init.d/vncserver

/etc/rc6.d/K99vncserver->../init.d/vncserver

/etc/rc2.d/S99vncserver->../init.d/vncserver

/etc/rc3.d/S99vncserver->../init.d/vncserver

/etc/rc4.d/S99vncserver->../init.d/vncserver

/etc/rc5.d/S99vncserver->../init.d/vncserver

Reboot your Ubutnu 14.04 system and test out your new VNC Server on Ubuntu 14.04

1

# reboot

You can login to your VNC Server with IP address or hostname/domain name by using RealVCN viewer or TightVNC viewer. You will be asked for your user VNC’s password.

When your VNC session starts the first time, Xfce4’s panel will ask you to choose “Use default config” or “One empty panel”. Choose/click on “Use default config”

Related

Comments

Thanks for a very well written tutorial. I have spent quite some time now trying to make VNC to an updated Ubuntu 14.04 machine work, but to no avail. Your post is recent and it seems you know very well what you are doing. However, even though I follow your steps exactly, I do not get VNC to work. My client is currently the tightVNC viewer in Windows.

What I want to do is to use a separate frame buffer (desktop) and that is why I want tightVNC. x11vnc works fine but gives me just a copy of the desktop being displayed on the server side.

I have tried trillions of different .vnc/xstartup to no avail. I am new to this so I really just follow the posts I read for now. I haven’t found anywhere to read up on this configuration file; what you can and cannot do etc.

Most xstartup settings just give me a grey background and the mouse cursor. If I enable the following two lines

Use a clean xstartup file (blank), don’t mind the default xstartup. Try to use the xstartup from the second answer from askubuntu link above if you want to use gnome (I didn’t try myself). Or simply use xfce4 instead of gnome.

Also, what packages have you installed so far? and are you using ubuntu-desktop or ubuntu-server ?

update: lol I finally can load up gnome w/ vncserver. I used ubuntu-desktop package, with some extra from askubuntu

Hi, thanks for the great tutorial. How do I make it so that the GUI doesn’t show up if I plug a monitor into the server itself? I went with xubuntu-desktop this time, I had gnome on a Server 12.04 install before upgrading and it never showed the GUI if I plugged a monitor in, only via VNC. It’s not important, I just liked it that way.

Hello please how can i make VNC server start at boot in a normal ubuntu 14.04 install with Unity desktop. i have tried many outdated tutorials with no avail. Im running latest 5.2 VNC Server from realvnc.com. Thanks!

I don’t have realvnc license so I didn’t try with realvnc server. I use vnc4server instead, follow my instructions and you should be able to make vnc server work on Ubuntu 14.04. Another thing, I don’t think Unity will work over VNC, you properly want to install xfce4 package, and use xfce4 for VNC rather than Unity.

Thanks very much with this detailed guide. please correct me if wrong : Just for users who want to have Wine on this, install Wine before ‘starting vnserver'; Wine is adding lines to xstartup file which should keep those lines thereafter.

I followed your post installing gnome-core, xfce4, vnc4server. Ran vncserver. Edited xstartup, but did not do the rest. Now when I try to connect, all I get is a terminal but not full desktop session. I tried different version of xstartup without success.

Today I found the problem. I did not kill the server before editing xstartup so changes did not take effect. Now everything is fine.

Just so you know, I uninstalled and reinstalled things to check what are needed. All I need is just xfce4, but gnome-core and others are not needed.

The only small problem I have now is the tab function. In linux the tab function is very useful. E.g.when you want to cd to a directory, you just need to type in a part of the directory name then tab to display the rest. when I connect to my desktop running Ubuntu from my macbook via VNC, this tab function does not work.

good to hear you have your vnc ser er up and running. I mainly use vnc to do some web surfing myself and its good to have some extra environment to do some developing, beside that I dont use the GUI that much from the remote system. I also noticed some of the keys dont work when I use vnc, if I remember correctly these are “e” and “d”. Different set keys dont work with different distro and/or window manager when you use vnc.

hi. great guide and all is working….but i’ve a little problem when connect to a vnc session is all ok But when i logout, all i obtai is a green page Then I cannot log again until I restart the vnc service. (using ex external ssh conection) I’m looking around for a solution … but sill nothing… May you help me? Thx Matteo

I have the same problem. If I just simple close the VNC connection, things are fine. But if I logout then it won’t give me an option to log back in. Closing VNC connection does not help because next time I connect, it just give me a blank screen again with no option to login. Killing the VNC then restarting it fix the issue, but this is not convenient at al. So I am looking for a solution too.

Thank you. Worked fine – the only part that slowed me was not knowing the command to launch the viewer. Here on my home LAN I used: $ vncviewer 192.168.1.115:1 The window title says it’s TightVNC: vncuser’s X desktop (ASR_PC:1) I’m using Xubuntu on both PCs, not Gnome or Unity. Is there a GUI for the login?

A PC running Xubuntu is the host, the VNC server. I’m logging in remotely using a PC that also is running Xubuntu. I don’t see a GUI app that asks me what remote host I want to connect to. Instead I use the command line as above. Is there a GUI I’m missing, or don’t know I have? I don’t find a GUI like the image “New TightVNC Connection” near the end of your blog.

xscreensaver: 09:50:12: This is probably because you’re logging in as root. You shouldn’t log in as root: you should log in as a normal user, and then `su’ as needed. If you insist on logging in as root, you will have to turn off X’s security features before xscreensaver will work.

(polkit-gnome-authentication-agent-1:10617): polkit-gnome-1-WARNING **: Failed to register client: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.gnome.SessionManager was not provided by any .service files

Hi, I’ve got SSH tunnelling working both locally and from outside the local network but where do I add the -localhost switch to only allow “local” IPs to connect? I want the VNC server to be unreachable if not connecting through an SSH tunnel.

So far I’ve tried adding -localhost to the VNCSERVERARGS[1] variable in /etc/vncserver/vncservers.conf ( VNCSERVERARGS[1]=”-geometry 1280×1024 -localhost”) and also when the vncserver command is put together in /etc/init.d/vncserver, so the line reads:

Thank you! I have been trying to find a remote desktop that works since I upgraded to 14.04, and the “nomachine” I was using just got a black screen.. I followed your steps, and it work perfectly the first time! Again Thank you!

How do I reset everything back the the way it was before following this procedure? I don’t really care for Xubuntu and now it’s my only GUI. Also I notice that when I have it up, there’s a wine box as well as a black hole rectangle that can be moved around the screen. All this makes me want to go back to my original desktop ubuntu and try something else. Thanks. P.S. I’m running this is Vbox VM as guest OS.

Hi Nam Huy I have followed your tutorial and I can’t get the vncserver to work. I tried both the xstartup files that you have mentioned and I always get a grey hatched screen. I have tried changing the lines in xstartup but I am no expert and was not really sure what I was doing with those files. I have wasted 2 days trying to set this up and I would like to seek your help on this.

I’m having an issue with your vncserver file starting up. I’ve made executable, etc. I can get everything to work if I start things manually. I did find another tutorial that did show another vncserver file that does work, but its locked to a specific user (which you must modify to match your own environment).

If you use my /etc/init.d/vncserver file, you will have to create extra /etc/vncserver/vncservers.conf file because rather store & call each user in /etc/init.d/vncserver. The one from digitalocean that guy store all user’s settings in the same file which is /etc/init.d/vncserver.

Sponsored Links

Nam Huy Linux delivers Linux tutorials, news, tips & tricks, and other open source php based scripts. We cover many popular Linux distributions and PHP scripts from Debian, Ubuntu, Linux Mint, Fedora, Centos, and Red Hat to WordPress, PHPbb, etc... We test every single tutorial at least twice before publish.