Tutorial

How To Install and Configure VNC on Ubuntu 14.04

Published on October 23, 2014
How To Install and Configure VNC on Ubuntu 14.04
Not using Ubuntu 14.04?Choose a different version or distribution.
Ubuntu 14.04

Introduction

VNC, or “Virtual Network Computing”, is a connection system that allows you to use your keyboard and mouse to interact with a graphical desktop environment on a remote server. VNC makes managing files, software, and settings on a remote server easier for users who are not yet comfortable with working with the command line.

In this guide, we will be setting up VNC on an Ubuntu 14.04 server and connecting to it securely through an SSH tunnel. The VNC server we will be using is TightVNC, a fast and lightweight remote control package. This choice will ensure that our VNC connection will be smooth and stable even on slower Internet connections.

Prerequisites

Before you begin with this guide, there are a few steps that need to be completed first.

You will need an Ubuntu 14.04 server installed and configured with a non-root user that has sudo privileges. If you haven’t done this yet, you can run through steps 1-4 in the Ubuntu 14.04 initial server setup guide to create this account.

Once you have your non-root user, you can use it to SSH into your Ubuntu server and continue with the installation of your VNC server.

Step One — Install Desktop Environment and VNC Server

By default, most Linux server installations will not come with a graphical desktop environment. If this is the case, we’ll need to begin by installing one that we can work with. In this example, we will install XFCE4, which is very lightweight while still being familiar to most users.

We can get the XFCE packages, along with the package for TightVNC, directly from Ubuntu’s software repositories using apt:

sudo apt-get update
sudo apt-get install xfce4 xfce4-goodies tightvncserver

To complete the VNC server’s initial configuration, use the vncserver command to set up a secure password:

vncserver

(After you set up your access password, you will be asked if you would like to enter a view-only password. Users who log in with the view-only password will not be able to control the VNC instance with their mouse or keyboard. This is a helpful option if you want to demonstrate something to other people using your VNC server.)

vncserver completes the installation of VNC by creating default configuration files and connection information for our server to use. With these packages installed, you are ready to configure your VNC server and graphical desktop.

Step Two — Configure VNC Server

First, we need to tell our VNC server what commands to perform when it starts up. These commands are located in a configuration file called xstartup. Our VNC server has an xstartup file preloaded already, but we need to use some different commands for our XFCE desktop.

When VNC is first set up, it launches a default server instance on port 5901. This port is called a display port, and is referred to by VNC as :1. VNC can launch multiple instances on other display ports, like :2, :3, etc. When working with VNC servers, remember that :X is a display port that refers to 5900+X.

Since we are going to be changing how our VNC servers are configured, we’ll need to first stop the VNC server instance that is running on port 5901:

vncserver -kill :1

Before we begin configuring our new xstartup file, let’s back up the original in case we need it later:

mv ~/.vnc/xstartup ~/.vnc/xstartup.bak

Now we can open a new xstartup file with nano:

nano ~/.vnc/xstartup

Insert these commands into the file so that they are performed automatically whenever you start or restart your VNC server:

#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &

The first command in the file, xrdb $HOME/.Xresources, tells VNC’s GUI framework to read the server user’s .Xresources file. .Xresources is where a user can make changes to certain settings of the graphical desktop, like terminal colors, cursor themes, and font rendering.

The second command simply tells the server to launch XFCE, which is where you will find all of the graphical software that you need to comfortably manage your server.

To ensure that the VNC server will be able to use this new startup file properly, we’ll need to grant executable privileges to it:

sudo chmod +x ~/.vnc/xstartup

Step Three — Create a VNC Service File

To easily control our new VNC server, we should set it up as an Ubuntu service. This will allow us to start, stop, and restart our VNC server as needed.

First, open a new service file in /etc/init.d with nano:

sudo nano /etc/init.d/vncserver

The first block of data will be where we declare some common settings that VNC will be referring to a lot, like our username and the display resolution.

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

Be sure to replace user with the non-root user that you have set up, and change 1024x768 if you want to use another screen resolution for your virtual display.

Next, we can start inserting the command instructions that will allow us to manage the new service. The following block binds the command needed to start a VNC server, and feedback that it is being started, to the command keyword start.

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

The next block creates the command keyword stop, which will immediately kill an existing VNC server instance.

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

The final block is for the command keyword restart, which is simply the two previous commands (stop and start) combined into one command.

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

Once all of those blocks are in your service script, you can save and close that file. Make this service script executable, so that you can use the commands that you just set up:

sudo chmod +x /etc/init.d/vncserver

Now try using the service and command to start a new VNC server instance:

sudo service vncserver start

Step Four — Connect to Your VNC Desktop

To test your VNC server, you’ll need to use a client that supports VNC connections over SSH tunnels. If you are using Windows, you could use TightVNC, RealVNC, or UltraVNC. Mac OS X users can use the built-in Screen Sharing, or can use a cross-platform app like RealVNC.

First, we need to create an SSH connection on your local computer that securely forwards to the localhost connection for VNC. You can do this via the terminal on Linux or OS X via the following command:

(Remember to replace user and server_ip_address with the username and IP you used to connect to your server via SSH.)

ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address

If you are using a graphical SSH client, like PuTTY, use server_ip_address as the connection IP, and set localhost:5901 as a new forwarded port in the program’s SSH tunnel settings.

Next, you can use your VNC viewer to connect to the VNC server at localhost:5901. Make sure you don’t forget that :5901 at the end, as that is the only port that the VNC instance is accessible from.

Once you are connected, you should see the default XFCE desktop ready for configuration and use! It should look something like this:

First VNC
connection

Once you have verified that the VNC connection is working, add your VNC service to the default services, so that it will automatically start whenever you boot your server:

sudo update-rc.d vncserver defaults

Conclusion

You should now have a secured VNC server up and running on your Ubuntu 14.04 server. Now you’ll be able to manage your server’s files, software, and settings with an easy-to-use graphical interface.

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 author(s)

Josh Barnett
Josh Barnett
See author profile
Category:
Tutorial

Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
70 Comments
Leave a comment...

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!

If you get any trouble connecting with VNC client I had to remove the -localhost flag from /etc/init.d/vncserver OPTIONS var Than restart the vncserver and reconnect with client.

ikatalan’s suggestion should be followed. Tut flowed really nicely, with appropriate level of explanation in my view. But the localhost flag did need removal.

Where and how to remove flag. Can you provide us with code for PUTTY ?

This worked for me, was scratching my head loads! Thank you!

without -localhost flag works and restart vncserver

sudo nano /etc/init.d/vncserver

remove -lovalhost

sudo service vncserver restart

then I use TigerVNC Client on Manjaro OS

ip:1 password for vncserver above defined

I notice that tab key is’nt working as expected after following this guide. So i found the workaround on : the following website Pasted here:

edit
~/.config/xfce4/xfconf/xfce-perchannel-xml/xfce4-keyboard-shortcuts.xml

find the line 

<property name="&lt;Super&gt;Tab" type="string" value="switch_window_key"/>

and change it to 

<property name="&lt;Super&gt;Tab" type="empty"/>

reboot or whatever and then tab will work properly!

I have no idea why but when using vnc this file seems to override tab's normal behaviour and makes it into a switch window key.

Hi, thanks for tutorial, it’s very good. But how I can enable clipboard between my computer and server? Also can enable file transfer?

You need an SSH client (like Cyberduck on Mac OS) for file transfer (or use scp in a Shell).

I’m very new to Ubuntu but I was able to understand and get thur most of the steps however I’m having problems with step 4 setting up the SSH connection. I’m trying to connect to my Ubuntu server from a Windows 7 computer. When I enter the ssh command on my Ubuntu server I get an error message “address already in use”. My command looks like this

ssh -L 5901:127.0.0.1:5901 -N -f -l shandzus 172.16.10.29

HI at all, thank Josh for this tutorial.

I have a problem in step 3

when I try using the service, I start the new VNC server writitng in shell

*******SHELL doxos@doxos-DeskTop:~$ sudo service vncserver start [sudo] password for doxos:

  • À partir vncserver pour l’utilisateur’doxos’ sur le localhost:1…
    Couldn’t start Xtightvnc; trying default font path. Please set correct fontPath in the vncserver script. Couldn’t start Xtightvnc process.

Unrecognized option: -:1 use: X [:<display>] [option]


have you any suggestions to resolve this issue???

thanks a lot

try this apt-get install xfonts-base

Thank you very much for this awesome tutorial. Very easy to understand, clear and every step well explained.

Does Step 4, specifically the “ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address” code need to be run on the remote machine that vncserver is being installed on, or the local machine that we’re connecting from?

I answered my own question, “ssh -L 5901:127.0.0.1:5901 -N -f -l user serveripaddress” is run on the local machine.

Best tutorial I could find on the subject.

Hi, Thanks for the tutorial, it is really amazing! I have only one problem though-when I am trying to access as a client to the computer I installed the vnc on, I get a grey screen. Does anyone know what the problem might be?

Thanks

Run: chmod +x xstartup and restart the vncserver

I am getting the grey screen as well. I ran the chmod +x xstartup command but i get an error that xstartup directory does not exist. i have killed the vncserver service and start it up agin and get a message A vnc server is already running as :1 i connect with tight vnc and still receive the gray screen. Any help would be gladly appreciate it. Thank you!

check spelling of this file ~/.vnc/xstartup

Hi there - I followed everyone’s comments but still get grey screen upon connecting. I am connecting to Ubuntu 14.04.05 Desktop, not server and it shouldn’t make a difference. Unity is running also. Any other comments welcomed.

I am also getting a blank screen after logging into vnc

Step Four using PuTTy and TightVNC Viewer on Windows:

  • Download the installer for TightVNC
  • Choose custom setup type, only install TightVNC Viewer (optional).
  • In PuTTy, go to Session, select and load the settings you use to connect to your server, then go to Connection > SSH > Tunnels. Type 5901 in Source port and localhost:5901 in Destination. Click Add. Go back to Session, enter a new name for these settings and save them for later use. Now click Open.
  • Fire up TightVNC Viewer, enter localhost::5901 as remote host and click connect. You will be prompted for your password. Done !

Thanks for this. I would add that you need to actually login through putty first before connecting with TightVNC.

This should be in last section of the article. Thank you very much.

I cannot connect, it says "This server does not have a valid password enabled. Until a password is set, incoming connections cannot be accepted. Any solutions ?

Thanks it worked on VNC viewer as well, but then i connect to my ubuntu server i get gray-screen, any solutions? http://postimg.org/image/jlktl8w1z/

Thanks it’s worked :D

Thanks a bunch for the very clear writeup on this part. I had gotten as far as the Tunnels in PuTTy but couldn’t quite make the rest work.

Cheers! Very much appreciated.

Hi Josh, thanks for posting this tutorial - very clear - excellent job. As an Ubuntu 14.04 newbie, this is very useful. Unfortunately, I ran into a snag at the very last part of actually getting a remote viewing session up and running. I tried accessing natively from Mac OS X 10.10.2 (CMD+K, vnc://localhost:5901) - I get a Screen Sharing prompt for pwd, but local nor remote passwords work. Using Real VNC from a Win 7 Pro PC, produces “The connection was refused by the host computer”. Using TightVNC (tightvnc-jviewer.jar) on the Mac, accepts the remote Ubuntu computer’s password, but then gets stuck with “Handshaking with remote host” and then it just sits there. Any thoughts?

The password is for the User you set at the beginning of Step 3.

This comment has been deleted

    Make sure you have run “vncserver” command.

    Fantastic tutorial!

    However, I have seen the last snapshot in this tutorial, and I cannot click and type anything. Then, screensaver is opened…I just cannot do anything.

    Anyone has a solution?

    I suspect you are using the read-only password.

    Thanks for this great tutorial. Exactly what I needed, and all in one place. Works flawlessly.

    Successfully connected to my server, but the icons is not there (menu icons, file manager folder icons) how do I fix it?

    Update: Got it, I have to update the appearance settings

    This comment has been deleted

      I’m having issues with TightVNC: Every time I’m trying to connect to hostname::5901 or hostname:5901 It leaves the message: “Connection has been gracefully closed”. Do you know where I could’ve failed ?

      Well maybe I’ve found where it comes from: This is what happen when trying to create an SSH connection:

      necrioss@danBoy:~$ ssh -L 5901:127.0.0.1:5901 -N -f -l necrioss 178.62.42.44
      necrioss@178.62.42.44's password:
      bind: Address already in use
      channel_setup_fwd_listener: cannot listen to port: 5901
      Could not request local forwarding.
      

      love it

      Thank you very much… This post work for me… I am trying to see if it also work well with X11 forwarding too… Thank you again!!

      See my comment below. X11 forwarding works well with XQuartz on Mac OS X.

      How can I use a desktop environment like in RedHat or Ubuntu?

      when I try to connect with putty I get the error: network error: connection refused

      This comment has been deleted

        Make sure you have run “vncserver” command.

        I followed all instructions… though getting grey screen while connecting via vnc… Any idea

        Did you ever get the grey screen resolved?

        I was also having this issue. After reviewing every step I found I had made a mistake on ~/.vnc/xstartup

        I had incorrectly typed “startxfc34 &” on the third line.

        I have updated it as below, and can connect using screen sharing with success.

        #!/bin/sh xrdb $HOME/.Xresources startxfce4 &

        Note: I am running Ubuntu Server 14.04 on a VirtualBox guest on an OSX host.

        Every thing are fine BUT “Step Four — Connect to Your VNC Desktop” is only time pass. we can not understand. Please update it for windows user.

        I cant connect locally because im using a pc at home, how do i use a windows pc to connect to the vnc? whenever i try it says it actively tried to refuse or just refused to connect. what is wrong?

        Great guide, but I can’t connect remotely to my VNC server system. The SSH tunnel works perfectly, but when I open my VNC viewer and try to connect to localhost:5901 it doesn’t detect any VNC servers.

        Have you tried to remove the -localhost flag in the options file? (See first comment.)

        great article. Is it possible to resume the session when we logout and re-login from VNC connection?

        Just close your VNC client. The session will still run on the defined virtual display (:1).

        I experienced crashes of the VNC server with applications using OpenGL (like Chrome or Gephi). Used vnc4server instead of tightvncserver, solved. It also enhanced the quality in Chicken (VNC client for Mac, use instead of Screen Sharing if you are experiencing issues with getting your clipboard contents to the remote server). Don’t know about the performance on the server side, as I don’t care on the machine I’m using atm, I think it’s worse than tightvnc, but it doesn’t crash.

        If you’re going to use applications, which use OpenGL (or 64bit applications, which I also have read are causing issues), try this in Step One:

        sudo apt-get update
        sudo apt-get install xfce4 xfce4-goodies vnc4server
        

        If you also want to have a complete desktop environment, use

        sudo apt-get update
        sudo apt-get install xubuntu-desktop vnc4server
        

        but be aware that this increases the installation to 1GB and installs a lot of stuff you don’t need on a server usually (Firefox, Bluetooth support …). It provides you with a complete working environment and you don’t need to add a ppa repository though.

        Everything else should work the same way.

        If you’ve already gone through the whole tutorial (great tutorial, thx!) just remove tightvncserver

        sudo apt-get remove tightvncserver
        

        and install vnc4server instead:

        sudo apt-get install vnc4server
        

        No further adjustment of the other files required, as the files seem to be not affected by the installation.

        Good alternative on Mac OS X for starting a VNC, if you only want to start a certain application, is X11 forwarding. Just install XQuartz (http://xquartz.macosforge.org/landing/) and start Terminal.

        type:

        ssh -X -C -c blowfish YOURUSERNAME@YOURHOST
        

        to establish an encrypted (faster encryption with -c blowfish than the standard), compressed (-c), X-session.

        Then just start the programm you want to use, e.g.

        firefox
        

        It will open in a window on your Desktop.

        If you want the whole desktop environment (even if this is often overkill, you could just start the filemanager), start

        startxfce4
        

        go in the preferences of XQuartz/X11 and tick Output->Full Screen Mode.

        This gives better performance in most setups than VNC from my perspective and is easier to setup. I don’t know about feasibility on Windows though.

        Have a good day!

        DO i have to change the user name in this code to my user or shall I leave it as it is? case “$1” in start) log_action_begin_msg “Starting vncserver for user ‘${USER}’ on localhost:${DISPLAY}” su ${USER} -c “/usr/bin/vncserver ${OPTIONS}” ;;

        NOTE: USER - should be changed or not?

        Kamal Nasser
        DigitalOcean Employee
        DigitalOcean Employee badge
        May 11, 2015

        No, USER is the variable’s name. ${USER} will be replaced with the value of the variable when the script is run.

        Hi, I’m having trouble connecting with UltraVNC I get “Connection failed” possible causes:

        • another user is already listening on this ID
        • bad connection

        the putty connection works perfectly. when I run this command (adjusted with my credentials of course): ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address

        I get:

        bind: Address already in use channel_setup_fwd_listener: cannot listen to port: 5901

        so I’m guessing that’s already running?

        any help would be golden!

        thanks in advance

        this is what putty displays when i try to use vnc: channel 1017: open failed: administratively prohibited: open failed

        please help about this errors:

        insserv: warning: script ‘K01vncserver’ missing LSB tags and overrides insserv: warning: script ‘vncserver’ missing LSB tags and overrides

        I get /etc/init.d/vncserver: line 8: ./lib/lsb/init-functions: Permission denied when I start VNC server any idea Why?

        I followed all instructions… though getting grey screen while connecting via vnc… Any idea

        Did you ever get the grey screen resolved?

        I was also having this issue. After reviewing every step I found I had made a mistake on ~/.vnc/xstartup

        I had incorrectly typed “startxfc34 &” on the third line.

        I have updated it as below, and can connect using screen sharing with success.

        #!/bin/sh xrdb $HOME/.Xresources startxfce4 &

        Note: I am running Ubuntu Server 14.04 on a VirtualBox guest on an OSX host.

        Every thing are fine BUT “Step Four — Connect to Your VNC Desktop” is only time pass. we can not understand. Please update it for windows user.

        I cant connect locally because im using a pc at home, how do i use a windows pc to connect to the vnc? whenever i try it says it actively tried to refuse or just refused to connect. what is wrong?

        Great guide, but I can’t connect remotely to my VNC server system. The SSH tunnel works perfectly, but when I open my VNC viewer and try to connect to localhost:5901 it doesn’t detect any VNC servers.

        Have you tried to remove the -localhost flag in the options file? (See first comment.)

        great article. Is it possible to resume the session when we logout and re-login from VNC connection?

        Just close your VNC client. The session will still run on the defined virtual display (:1).

        I experienced crashes of the VNC server with applications using OpenGL (like Chrome or Gephi). Used vnc4server instead of tightvncserver, solved. It also enhanced the quality in Chicken (VNC client for Mac, use instead of Screen Sharing if you are experiencing issues with getting your clipboard contents to the remote server). Don’t know about the performance on the server side, as I don’t care on the machine I’m using atm, I think it’s worse than tightvnc, but it doesn’t crash.

        If you’re going to use applications, which use OpenGL (or 64bit applications, which I also have read are causing issues), try this in Step One:

        sudo apt-get update
        sudo apt-get install xfce4 xfce4-goodies vnc4server
        

        If you also want to have a complete desktop environment, use

        sudo apt-get update
        sudo apt-get install xubuntu-desktop vnc4server
        

        but be aware that this increases the installation to 1GB and installs a lot of stuff you don’t need on a server usually (Firefox, Bluetooth support …). It provides you with a complete working environment and you don’t need to add a ppa repository though.

        Everything else should work the same way.

        If you’ve already gone through the whole tutorial (great tutorial, thx!) just remove tightvncserver

        sudo apt-get remove tightvncserver
        

        and install vnc4server instead:

        sudo apt-get install vnc4server
        

        No further adjustment of the other files required, as the files seem to be not affected by the installation.

        Good alternative on Mac OS X for starting a VNC, if you only want to start a certain application, is X11 forwarding. Just install XQuartz (http://xquartz.macosforge.org/landing/) and start Terminal.

        type:

        ssh -X -C -c blowfish YOURUSERNAME@YOURHOST
        

        to establish an encrypted (faster encryption with -c blowfish than the standard), compressed (-c), X-session.

        Then just start the programm you want to use, e.g.

        firefox
        

        It will open in a window on your Desktop.

        If you want the whole desktop environment (even if this is often overkill, you could just start the filemanager), start

        startxfce4
        

        go in the preferences of XQuartz/X11 and tick Output->Full Screen Mode.

        This gives better performance in most setups than VNC from my perspective and is easier to setup. I don’t know about feasibility on Windows though.

        Have a good day!

        DO i have to change the user name in this code to my user or shall I leave it as it is? case “$1” in start) log_action_begin_msg “Starting vncserver for user ‘${USER}’ on localhost:${DISPLAY}” su ${USER} -c “/usr/bin/vncserver ${OPTIONS}” ;;

        NOTE: USER - should be changed or not?

        Kamal Nasser
        DigitalOcean Employee
        DigitalOcean Employee badge
        May 11, 2015

        No, USER is the variable’s name. ${USER} will be replaced with the value of the variable when the script is run.

        Hi, I’m having trouble connecting with UltraVNC I get “Connection failed” possible causes:

        • another user is already listening on this ID
        • bad connection

        the putty connection works perfectly. when I run this command (adjusted with my credentials of course): ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address

        I get:

        bind: Address already in use channel_setup_fwd_listener: cannot listen to port: 5901

        so I’m guessing that’s already running?

        any help would be golden!

        thanks in advance

        this is what putty displays when i try to use vnc: channel 1017: open failed: administratively prohibited: open failed

        please help about this errors:

        insserv: warning: script ‘K01vncserver’ missing LSB tags and overrides insserv: warning: script ‘vncserver’ missing LSB tags and overrides

        I get /etc/init.d/vncserver: line 8: ./lib/lsb/init-functions: Permission denied when I start VNC server any idea Why?

        Hi,

        When i try and start the service it get the following Failed to start vncserver.service: Unit vncserver.service failed to load: No such file or directory

        Everything looks ok and i have triple checked the steps and have not missed anything.

        Does vncserver work when trying to connect to a Unity desktop?

        I am experiencing problems with VNC server. Everything is properly configured, I can connect with the VNC client from my computer and everything works perfect. But after a couple of hours without connect, VNC server stops working and I must reboot the droplet to run the service again (restart the service give me an error). I need to keep running VNC server indefinitely to keep running an application with GUI. Can someone help me?

        I love DigitalOcean because you care about your users <3

        Hi! Thanks for this tutorial. I followed it step by step but i am having trouble on step three and i am stuck there. When i type: ~$ sudo vncserver start this happens: vncserver: Wrong type or access mode of /home/getin/.vnc

        when i try by this way: ~$ sudo /etc/init.d/vncserver start i get this: […] Starting vncserver (via systemctl): vncserver.serviceFailed to start vncserver.service: Unit vncserver.service failed to load: No such file or directory. failed!

        ;/

        What did i did wrong? is that because i am using ubuntu 15?

        thanks

        This comment has been deleted

          If you get any trouble connecting with VNC client I had to remove the -localhost flag from /etc/init.d/vncserver OPTIONS var Than restart the vncserver and reconnect with client.

          Very Nice !

          did anyone figure the grey screen out? i am having the same isue

          I am having trouble with this line: ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address I know what the username is but I do not understand what the ip address should be I also had trouble getting the ssh tunnel configured and working as I get a refused connection when trying to open the ssh port 22 from the local host. How do you open that port?

          Thank you,

          I tried this solution on an Ubuntu 14.04.3 desktop installation. I ended up with a login screen that wouldn’t go away, essentially an unstartable Ubuntu installation. I also found that the client computer would not execute the ssh commands as described in this tutorial, as other commenters have noted.

          It is really much easier to install and run vnc than what is described here. I don’t guarantee favorable results from doing what follows, but it worked for me.

          Install tightvncserver, xtightvncviewer, and gnome-panel by either Ubuntu Software Center or sudo apt-get install.

          From the command line, run vncserver, and enter your passwords of choice.

          If you are planning to run vnc on a remote computer over the internet, you do need some sort of security. If you choose to use ssh, then I can’t help, because the method described here did not work for me. I have personally found that using vnc on the internet leads to numerous attempts to login from vandals, sufficient to cause the server to autoshutdown, if you use the standard ports. Such attacks are not nearly as likely if you use nonstandard ports such as 23. Therefore, you might enter in the command line when you start your vnc server

          vncserver :23

          and then you have a vncserver running on port 5923, not likely to be targeted by the usual internet vandal, although anyone with a port scanner can detect open ports if they are really serious. Not too many of these, in my experience. Tightvnc makes opening on ports other than 5901 easy.

          You can access vnc by entering

          vncviewer 127.0.0.1:23

          on the command line, if you have already started your vnc server on port 23 as just described. However, if you have changed nothing else, what you will then get is a vncserver window that is just a blank gray screen. In order to improve this untenable situation, you may wish to try the minimalist solution that I have developed by experiment.

          Close the vnc window. On the command line, enter

          vncserver -kill :23

          and then open the vnc startup file “xstartup” in /home/{your system username}/.vnc folder. You will need to have root access to alter this file, which is what is needed next. My way of getting this in Ubuntu is to enter “sudo su” on the command line, then the password of your administrator account, then “nautilus”, which will open a file manager window with root privileges. You then need to go to your application menubar and View - Show Hidden Files, which will expose the hidden .vnc folder, which contains xstartup. Clicking on the xstartup file should then bring up the file in a text editor with root privileges, making the file alterable. This file should be modified to read

          #!/bin/sh xsetroot -solid black # (or your favorite color) x-terminal-emulator -geometry 80x24+10+10 -ls -title “$VNCDESKTOP Desktop” & metacity &

          and then saved. You could make a backup file, but Ubuntu has already done this if you have followed these instructions, filename xstartup~.

          Now try

          vncserver :23

          and

          vncviewer 127.0.0.1:23

          again on the command line.

          I have tried a bunch of different things on the subsequent vnc window, but the only ones that have worked for me at all are as follows. You should see a terminal window, which you should not close. If you now enter on the command line

          gnome-panel

          you will see a top menubar that gives you “Applications” and “Places”, the gnome drop-down menus. In this configuration, some of the programs displayed will run in the vnc window, whereas others will open in the main Ubuntu window. You can then open another terminal and enter on the command line

          sudo gnome-panel

          which will permit opening the programs in “Applications” differently. I did not explore this subject with all of the different programs available in “Applications” but found that I needed both of the just-described solutions just to use the few programs important to me. For one example, VirtualBox, which is available from Ubuntu Software Center, is very handy for running complete operating system installations within Ubuntu. You can install your operating system of choice in VirtualBox, then tweak settings and install programs of your choice, and then you have a virtual disk that can be transferred at will from one Ubuntu machine to another with all your stuff. If you want to use this program remotely by vnc, you need to use the

          gnome-panel

          command line option, because if you try the “sudo gnome-panel” option you get a blank window version of VirtualBox. If instead you try to open Applications/Accessories/Files when you have invoked “gnome-panel” on the commandline, the file manager (nautilus, non-root) will open in the main Ubuntu window. In order to open the file manager in the vnc window, you need to have run “sudo gnome-panel” in the vnc terminal command line beforehand.

          I am submitting this in the hope that it will be helpful to people like me who are not programmers but who just want to have a functioning vnc server on Ubuntu 14.04. I am also hoping that somebody who knows more than I do will pick up on this and explain, for example, how the Unity Launcher could be opened by default when the vnc window opens, instead of the user having to go through the gnome-panel rigmarole that worked for me. If you have anything to say on this subject, please post a reply. I again make no guarantees, but this did work for me on a fresh Ubuntu installation without any more modification than just described.

          anyone knows how can i connect to vnc using Android, is it possible?

          Good night,

          When I start the server I get this error “Xlib: extension “RANDR” missing on display “:1”. vnc”

          Hi everybody…

          I also got the same error some of you got, about the gray screen. In my case, I ran wrong the follow command:

          sudo apt-get install xfce4 xfce4-goodies tightvncserver

          once I ran:

          sudo apt-get install xfce4-goodies tightvncserver

          because I didn’t type “xfce4”, the apt-get didn’t install the desktop (even installing its goodies, God nows why!!!). So, try running again just the xfce4 installer, like this:

          sudo apt-get install xfce4

          Worked for me! Merry Christmas!

          Thank you! I set up the vnc server successfully.

          But if i open chrome, it will open at the server side UI, not the client side…

          I am using Cinnamon 2.6.13 on Ubuntu 14.04. Is there any way to use the cinnamon instead of xfce? (connect to current session)

          very helpful and extremely straightforward. this is quality tech advice.

          Side note: this WILL not work (at least without a few tweaks) if you have Ubuntu 15.04

          thanks for the tutorial. was very easy to follow. worked great. i have used other tutorials for this in the past but this one is simple and precise and explains the steps in more depth.

          I have problems understanding the SSH forwarding part.

          Does “ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address” create an “SSH tunnel”, if so, please consider using that word.

          Why is it not possible to just connect directly to the VPS from the VNC viewer? Why create this tunnel from localhost to the remote, and then connect to the localholst.

          And then I think the line below could be rewritten for doubtful confused people like myself. “(…) forwards to the localhost connection for VNC”. What is a/the “localhost connection”? Is that a term? Is it the localhost connection belonging to VNC, or is it a connection to VNC.

          “First, we need to create an SSH connection on your local computer that securely forwards to the localhost connection for VNC. You can do this via the terminal on Linux or OS X via the following command:”

          For Step 3, you should have left out the -localhost switch part and only mention it again in Step 4 like on the Debian tutorial as to not confuse some new users who might skip SSH tunneling part.

          You should also mention that File transfer with UltraVNC viewer and TightVNC server is not compatible.

          also I got warning: /etc/init.d/vncserver missing LSB information when invoking sudo update-rc.d vncserver defaults.

          Hello; Tank you very much for this toturial , I have following all the steps , but I have a problem : the port 5901 is always closed. When I execute the command :

          nmap -PN -p5901  @IP
          

          I have this result :

          Starting Nmap 6.40 ( http://nmap.org ) at 2016-04-24 09:10 UTC
          Nmap scan report for xxx.xxx.xxx.xxx
          Host is up (0.0014s latency).
          PORT     STATE  SERVICE
          5901/tcp closed vnc-1
          
          

          Can you tell me What I have to do in order to open it ? Thank you very much.

          Hello, I have this error:

          “Could not create /home/usuariovnc//.vnc.”

          I wish Digital Ocean would make an Ubuntu droplet that as already configure with all this stuff setup and working!!

          Thanks. Nice Article.

          To make it work on ubuntu 16.04 you will need to run this command:

          sudo systemctl enable vncserver.service

          Obsolete guide - packages won’t install :/

          I’m trying this on Ubuntu server 16.04 and when I get to trying to run VNC as a service, I’m greeted by the following error Failed to start vncserver.service: Unit vncserver.service not found.

          I can’t find any info on troubleshooting this. I can run the VNC server by executing /usr/bin/vncserver But after following this tutorial, TightVNC winn not run as a server. Can anyone tell me why Ubuntu can’t find vncserver.service?

          After step 3 I get an error “Failed to start vncserver.service: Unit vncserver.service not found” The vncserver file is in /etc/init.d. If I start vncserver on its own it runs. Am I missing anything?

          Hey, I got an error starting the server for the first time. I’m a horrible troubleshooter and even worse at linux, could anyone help?

          sudo service vncserver start /etc/init.d/vncserver: line 8 : ./lib/lsb/init-functions: Permission denied /etc/init.d/vncserver: line 11: log_action_begin_msg: command not found bash: /usr/bin/vncserver/: not a directory

          I am having a problem with step 4. I get an error ssh: connect to host “ipaddress” port 22: Connection refused. so i used $ ssh -L 5901:127.0.0.1:5901 -N -f -l user server_ip_address -p 6001 And know I get “ssh_exchange_identification: Connection closed by remote host”

          Here’s a tutorial for Ubuntu 16.04 LTS - https://www.youtube.com/watch?v=f-NS4IM3NEI

          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!

          Become a contributor for community

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

          DigitalOcean Documentation

          Full documentation for every DigitalOcean product.

          Resources for startups and SMBs

          The Wave has everything you need to know about building a business, from raising funding to marketing your product.

          Get our newsletter

          Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

          New accounts only. By submitting your email you agree to our Privacy Policy

          The developer cloud

          Scale up as you grow — whether you're running one virtual machine or ten thousand.

          Get started for free

          Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

          *This promotional offer applies to new accounts only.