Tutorial

How To Setup VNC For Ubuntu 12

Published on March 31, 2013
author

Bulat Khamitov

How To Setup VNC For Ubuntu 12

Status: Deprecated

This article is deprecated and no longer maintained.

Reason

Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates.

See Instead

This article may still be useful as a reference, but may not follow best practices or work on this or other Ubuntu releases. We strongly recommend using a recent article written for the version of Ubuntu you are using.

If you are currently operating a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:

Introduction

VNC stands for Virtual Network Computing, which allows you to connect to your server remotely, and be able to use your keyboard, mouse, and monitor to interface with that server.

Step 1 - Install VNC server and XFCE 4 desktop.

To get started, we will install a VNC server on Ubuntu 12.10 x64 Server droplet. Login as root and install packages:

apt-get -y install ubuntu-desktop tightvncserver xfce4 xfce4-goodies

Step 2 - Add a VNC user and set its password.

adduser vncpasswd vncIf you would like to get root as user vnc you would have to add it to sudoers file. Make sure you are logged in as root:echo "vnc ALL=(ALL) ALL" >> /etc/sudoersSet user vnc’s VNC Server password:su - vncvncpasswdexitThis step sets the VNC password for user ‘vnc’. It will be used later when you connect to your VNC server with a VNC client:

img

Now you can login as user ‘vnc’ and obtain root by running ‘sudo su -‘ and entering your password:

img

Step 3 - Install VNC As A Service

Login as root and edit /etc/init.d/vncserver and add the following lines:

#!/bin/bash
PATH="$PATH:/usr/bin/"
export USER="vnc"
DISPLAY="1"
DEPTH="16"
GEOMETRY="1024x768"
OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
. /lib/lsb/init-functions

case "$1" in
start)
log_action_begin_msg "Starting vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
;;

stop)
log_action_begin_msg "Stoping vncserver for user '${USER}' on localhost:${DISPLAY}"
su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
;;

restart)
$0 stop
$0 start
;;
esac
exit 0

Edit /home/vnc/.vnc/xstartup and replace with:

#!/bin/sh
xrdb $HOME/.Xresources
xsetroot -solid grey
startxfce4 &

Update file permissions and allow any user to start X Server:

chown -R vnc. /home/vnc/.vnc && chmod +x /home/vnc/.vnc/xstartup
sed -i 's/allowed_users.*/allowed_users=anybody/g' /etc/X11/Xwrapper.config

Make /etc/init.d/vncserver executable and start VNC server:

chmod +x /etc/init.d/vncserver && service vncserver start

Add your VNC server to automatically start on reboot:

update-rc.d vncserver defaults

Step 4 - Connect to your droplet with TightVNC

TightVNC is a great VNC client that allows SSH tunnel. It can be downloaded from http://www.tightvnc.com/download.php

Make sure to use IP::port as your remote host, where IP is your droplet’s IP and port is 5901:

img

You will be asked for VNC password that you specified in step 2 with vncpasswd:

img

And now you are connected:

img

Step 5 - Secure your VNC server session with encryption

A basic VNC server setup has no encryption, which makes it vulnerable to snooping.

We will create an SSH tunnel with Putty and connect to VNC via this tunnel.

First, we need to make sure VNC server only listens on localhost.

Edit /etc/init.d/vncserver and add -localhost to OPTIONS:

OPTIONS="-depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY} -localhost"

img

Restart VNC server:

/etc/init.d/vncserver restart

Make sure VNC server is only listening on localhost IP:

netstat -alpn | grep :5901

img

Download Putty from http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

For Windows: http://the.earth.li/~sgtatham/putty/latest/x86/putty.exe

Start Putty and enter your droplet IP under Session:

img

Don’t connect just yet.

Scroll down to Connection -> SSH -> Tunnels and Add New Forwarded Port and click Add:

img

Now you can connect by clicking Open. You can login as user vmc:

img

Make sure you don’t close this SSH session, as it creates a tunnel between your PC (localhost) and your droplet, mapping ports 5901 on both ends.

Connect with TightVNC to localhost::5901

img

Enter your VNC password from Step 3 above:

img

And you are now connected via a secure connection:

img

And you are all done!

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Bulat Khamitov

author

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
10 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Hi! I’m getting the following error: “sed: can’t read /etc/X11/Xwrapper.config: No such file or directory”

Can you help?

it works, but on file manager, why the icon for file & folder missing ?

Thx dude.

Hi,

How can i add another user for vnc

can i get help setting this up… i cant seem to do step 2 i did the adduser vnc part but cant do any thing after that as i dont no how…

i need help as i m new to all this i am stuck at step 2 i did the adduser vnc and password then dont no how to put this echo “vnc ALL=(ALL) ALL” >> /etc/sudoers in or what to do?

i installed TightVNC using wine in ubuntu 12.04

in step 5 at last i install putty in ubuntu 12.04 using after i added my ip as host name and click on “connect” so it give me “Connection refuse” error

hi, i follow your four step but confuse in fifth step i download tightvnc-1.3.10_unixsrc.tar.gz from http://www.tightvnc.com/download.php but how to install tightvnc-1.3.10 in ubuntu 12.04

Brilliant article, thank you. Had to take a few more steps to get it working, but all sorted. However, now I have one issue… I need to run Synaptic to repair broken dependencies so I can install memcached. Any ideas as to how I can run it under VNC? As VNC user is NOT root… I’d love to hear how and if it’s possible? The only reason I did this, was literally for Synaptic as I need to repair dependencies

Many thanks!

I just want to share something different I’ve done.

Instead of using TightVNC I’ve used Vinagre 3.10.2 as my VNC client, on top of my Ubuntu 10.4 local machine.

It’s advantage is that it offers natively the SSH tunnel connection, so that you don’t need to run Putty and TightVNC together, but only Vinagre.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more