This article is deprecated and no longer maintained.
Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates.
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:
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.
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
adduser vncpasswd vnc
If 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/sudoers
Set user vnc’s VNC Server password:su - vncvncpasswdexit
This step sets the VNC password for user ‘vnc’. It will be used later when you connect to your VNC server with a VNC client:
Now you can login as user ‘vnc’ and obtain root by running ‘sudo su -‘ and entering your password:
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
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:
You will be asked for VNC password that you specified in step 2 with vncpasswd:
And now you are connected:
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"
Restart VNC server:
/etc/init.d/vncserver restart
Make sure VNC server is only listening on localhost IP:
netstat -alpn | grep :5901
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:
Don’t connect just yet.
Scroll down to Connection -> SSH -> Tunnels and Add New Forwarded Port and click Add:
Now you can connect by clicking Open. You can login as user vmc:
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
Enter your VNC password from Step 3 above:
And you are now connected via a secure connection:
And you are all done!
Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.
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!
Thanks, superb article. Perhaps a custom image could be available with VNC? Would go in line with DO’s mission of simplicity.
Photos missing?!? Love the concept but would love to see the screenshots too.
all pics missing…
@Jack Keller @onyx808 Sorry for that, it was fixed two days ago. :]
I’m stuck at Step 4. I get this error message:
root@VNC:~# edit /etc/init.d/vncserver Warning: unknown mime-type for “/etc/init.d/vncserver” – using “application/octet-stream” Error: no “edit” mailcap rules found for type “application/octet-stream” root@VNC:~# Warning: unknown mime-type for “/etc/init.d/vncserver” – using “application/octet-stream” Warning:: command not found root@VNC:~# Error: no “edit” mailcap rules found for type “application/octet-stream”^C
@josephs.julian: You have to use a text editor to edit a file. I suggest nano - it’s more user friendly than other alternatives such as vim or emacs:
nano /etc/init.d/vncserver
I suggest Atom: https://github.com/atom/atom/releases/tag/v0.136.0
Thanks, very great and helpful tutorial, i only have one problem, i still have open port on my IP:5901
When i follow your steps and type netstat -alpn | grep :5901 i get both 127.0.0.1:5901 MYIP:5901
alexandar.n - did you follow the ‘Recommended Step’ ? You have to restart the VNC server after you edit config. Make sure you have “-localhost” added to OPTIONS in “/etc/init.d/vncserver”.
I have followed every step from tutorial, and it was showing both ip’s on service restart, but i rebooted server and now is showing only on localhost. Again, great tutorial!
How can I do step 4 (Edit /home/vnc/.vnc/xstartup and replace with:) without having xfce4 installed??? Just because I prefer the ubuntu’s desktop
@felipe.campos replace startxfce4 with startunity - let me know if it works.
when I type in “edit /etc/init.d/vncserver” while logged into vnc, it said no permissions to edit. so i used “chown -R vnc. /etc/init.d” to see if that would work (I have no idea what I’m doing). it seemed to work, but then I recieved the error “Warning: unknown mime-type for “/etc/init.d/vncserver” – using “application/octet-stream” Error: no “edit” mailcap rules found for type “application/octet-stream””
What am I doing wrong? Everything worked up until that point.
I should have read the comments. I’ll try that out
Sorry for the comment spam. It doesn’t appear that I have a vncserver file in /etc/init.d/ I’ve followed each step up until Step 4.
@jumpy.core what’s the output of “lsb_release -a”? “chown -R vnc. /etc/init.d” probably broke all of the permissions so you have to restore from a backup or find another way to fix /etc/init.d’s permissions.
lsb_release -a No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.04.2 LTS Release: 12.04 Codename: precise
There’s no actual vncserver file in init.d
Fortunately, If I messed it up that bad I’ll just wipe since it’s a pretty fresh install.
I recommend starting from scratch if you don’t have any data on this droplet yet. Let me know if it works on the new droplet :]
Hi, I’m having a similar problem to jumpy.core.
When I get to step 4 there’s no existing vncserver file to edit. “lsb_release -a” gives the following:
No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu 12.10 Release: 12.10 Codename: quantal
I’ve tried searching for vncserver but to no avail.
On my droplet I’m running Ubuntu 12.10 Server x64, and prior to following this tutorial the only command I;ve run is “apt-get update”
Any ideas what might be the problem?
@lifeofdave the file shouldn’t be there by default - you have to create it as “Step 4 - Install VNC As A Service” says.
Ahhhh. See thats what my problem was. It didn’t exist. The tutorial says to edit, which implies it already existed. I wiped for nothing xD
Okay everything is installed. I’m getting a connection actively refused when trying to connect via TightVNC & PuTTy. When I tried to restart vncserver i got this:
Killing Xtightvnc process ID 2920
@jumpy.core you didn’t wipe for nothing, /etc/init.d was messed up ;)
The solution for the .Xauthority timeout can be found here: https://www.digitalocean.com/community/questions/timeout-in-locking-authority-file-home-username-xauthority
it won’t work anymore… try then…
@lazaac: Do you get any errors? What part doesn’t work?
it seems like vnc was not installed, because there is no /etc/init.d/vncserver appeared…
@lazaac: The file doesn’t exist, you have to create it.
I’m getting a weird black-grey screen on login instead of the blue one depicted here[see the picture in the attachment]
http://i.imgur.com/MlqXXfl.jpg
So the question, "Why ? "
@sscarl2417: Is your droplet based on a Desktop image? If not, did you install the necessary packages for a gui?
Can somebody help me?
Solved ! Thank for tutorial , really good
@Kammal : What is that suppose to mean ? Yes, I did. Like I said I followed your tutorial and that shit screen appears everytime.
@sscarl2417: Try rebooting the droplet, does that fix it?
Did you follow this step:
Edit /home/vnc/.vnc/xstartup and replace with:
#!/bin/sh xrdb $HOME/.Xresources xsetroot -solid grey startxfce4 &
Try sshing into your droplet and running “startxfce4 &” manually, does that fix it?
I try to follow your tutorial without any results.
I found the following and it is work perfectly. http://rbgeek.wordpress.com/2012/06/25/how-to-install-vnc-server-on-ubuntu-server-12-04/
@tjcrandall: Install Cinnamon:
<pre> sudo add-apt-repository ppa:gwendal-lebihan-dev/cinnamon-stable sudo apt-get update sudo apt-get install cinnamon </pre>
And replace all occurrences of ‘startxfce4’ with ‘cinnamon’.
Let me know if that works.
I’v been followed all your steps(except the encryption steps) to install the vncserver on the remote, and tightvnc on my local machine. I can sucessfully login to the vnc port, but i cant input anything into the the terminal but the input can be done in the Firefox explore. Do you hv any ideas about this?
@francy.fu: Are you still experiencing this? Did you try rebooting your droplet?
after several restart, it’s ok now. Thanks for sharing!!!
@tjcrandall: Did you install ubuntu-desktop?
@tjcrandall: Awesome! Glad you got it working! :]
“If you would like to get root as user vnc you would have to add it to sudoers file.” what does that mean?
@Herit: It means that you have to add the ‘vnc’ user to sudoers (visudo) if you want to get root access when connecting to vnc.
I got this error on install WARNING:softwarecenter.db.update:The file: ‘/usr/share/app-install/desktop/sonic-visualiser:x-sonicvisualiser-layer.desktop’ could not be read correctly. The application associated with this file will not be included in the software catalog. Please consider raising a bug report for this issue with the maintainer of that application
Try running the following command:
<pre>sudo apt-get purge sonic-visualiser</pre>
Kamal, thank you for your expertise, I would just like to report that changing xstartup to use cinnamon does not work, i get gray screen, going back to gnome-session does. Also a follow up question. Is the session always active? can I logout of the session? I have a scenario where I work on desktop:0 at the office but when I am at home I like to connect to a new session at desktop:1, but i want to close the session when i am done so the next morning at work i am back logged in into a fresh desktop:0 session. It appears to me that this solution keeps my sessions alive all the time, until i restart the physical machine.
Try <pre>gnome-session --session=cinnamon</pre> instead – does that work?
I did everything you told and it didn’t fix. I upgraded to Ubuntu 13 and installed GNOME. XFCE is nothing but shit.
Thanks, just followed this, worked great :)
The paste function doesnt work between vncviewer and windows sometimes? How to fix it?
I got the solution from : http://thomas.patrickdepinguin.com/knowledgebase/tight-vnc :_) Copy text between client and server; using the clipboard It is possible to copy and paste between the client and the server. However, some issues can arise with this (see http://www.lugs.org.sg/pipermail/slugnet/2002-July/000590.html which lists “Q25 Can I cut and paste between the viewer and the server?” from a VNC FAQ.)
When you use RealVNC, the solution is to run the vncconfig program, like this:
vncconfig -nowin & However, vncconfig is not included with TightVNC. Using vncconfig from RealVNC together with a TightVNC server (1.3.10), I received the following error:
No VNC extension on display :84 Don’t panic though, there is an easy solution for TightVNC users, as listed at the above link: autocutsel (http://www.lepton.fr/tools/autocutsel). With this tool, you do no longer need vncconfig from RealVNC.
Simply run autocutsel like this:
autocutsel -s PRIMARY -fork and copying works like a charm.
You can put this command in ~/.vnc/xstartup. The commands listed in that file will be started automatically when a new vnc server is started.