How to install VNC server on an Ubuntu PC and remote connect to it from a Windows PC

Remote DesktopOn the Ubuntu 9.10 PC

The Ubuntu 9.10 PC shall hereafter be referred to as the SERVER.

  1. First of all, permit remote desktop on the SERVER:
    From the menubar, select System | Preferences | Remote Desktop

    1. Under Sharing:
      1. Check  Allow other users to view your desktop
      2. Check  Allow other users to control your desktop
    2. Under Security:
      1. Select  Require the user to enter this password
        and enter a password.
    3. Under Notification area:
      1. Select Only display an icon where there is somebody connected.
    4. Make a note of the network address and name of the SERVER as displayed in the Remote Desktop Preferences.
  2. Now ensure the required applications are installed:
    From the menubar, select System | Administration | Synaptic Package Manager

    1. In the quick search box, type vnc
    2. For each of the following four packages, right-click on them and select Mark for Installation
      1. vnc4server
      2. vnc4-common
      3. vinagre
      4. vino
    3. In the quick search box, type xinetd and install as described above.
    4. Finally, select Apply on the menubar to complete the installation.
  3. Now lets complete the VNC server install and configuration.
    Open up a command terminal:

    1. Run vncpasswd and enter the password that will be required by the client when attempting to connect to the SERVER
      vncpasswd
    2. Run the vncserver on display number 1  in order to generate the configuration files that we will subsequently customize.
      vncserver  :1
    3. If you were to connect via remote desktop from a client at this point, the resolution would be wrong and the screen would be plain grey.  Do not worry, we will fix that now. First, kill the vncserver process by issuing the command:
      vncserver  -kill  :1
    4. Edit the xstartup file in the folder .vnc (make a backup of the file first)
      gedit ~/.vnc/xstartup
    5. Ensure the file has the contents as follows:
    6. #!/bin/sh
      unset SESSION_MANAGER
      sh /etc/X11/xinit/xinitrc

  4. Finally, to run the vnc server on the SERVER (on display 1), issue the command:
    vncserver  :1  -depth 16  -geometry 1028x1024

On the Windows PC

The Windows PC shall hereafter be referred to as the CLIENT.

  1. Download and install the VNC viewer of your cloice.  I am using the free open source UltraVNC viewer.
    Note: UltraVNC is highly customizable.
  2. Run vncviewer.exe
    1. Enter in the network address of the SERVER pc (as recorded in step 1) immediately followed by a colon : and the display number. The following is an example of the format:
    2. 111.222.333.444:1

    3. Under Quick Options, select Auto.
    4. When prompted, enter the password specified in step 3.1
  3. Well Done!  You are now connected over remote desktop to the Ubuntu PC from your Windows PC.

How to configure the VNC server to run at bootup on the Ubuntu PC.

In practice, you will not want to logon to the SERVER just to initiate the VNC server.  Moreover, you may not even have a monitor for your Ubuntu Server, because you may be using the monitor as a dual screen for your primary desktop, as in my case.   :)
These instructions have been referenced from here.

To that end I will now explain how to ensure the VNC server is initialised at bootup time  (simply by switching on the SERVER).  All of the following steps will required you to be logged in as root.

  1. Open up a terminal and login as root
    sudo -i
  2. Run all the commands outlined in step 3 (for the Ubuntu PC) as root.
  3. Create a new file  in /etc/init.d called  vncserver and ensure it has the following contents:
    Note: Change the username (and optionally the other parameters) according to your circumstances.
  4. #!/bin/sh -e
    ### BEGIN INIT INFO
    # Provides:          vncserver
    # Required-Start:    networking
    # Default-Start:     S
    # Default-Stop:      0 6
    ### END INIT INFO
    PATH="$PATH:/usr/X11R6/bin/"
    # The Username:Group that will run VNC
    export USER="YOUR_USERNAME"
    #${RUNAS}
    # The display that VNC will use
    DISPLAY="1"
    # Color depth (between 8 and 32)
    DEPTH="16"
    # The Desktop geometry to use.
    #GEOMETRY="<WIDTH>x<HEIGHT>"
    #GEOMETRY="800x600"
    #GEOMETRY="1024x768"
    GEOMETRY="1280x1024"
    # The name that the VNC Desktop will have.
    NAME="your-vnc-server"
    OPTIONS="-name ${NAME} -depth ${DEPTH} -geometry ${GEOMETRY} :${DISPLAY}"
    . /lib/lsb/init-functions
    case "$1" in
    start)
    su ${USER} -c "/usr/bin/vncserver ${OPTIONS}"
    ;;
    stop)
    su ${USER} -c "/usr/bin/vncserver -kill :${DISPLAY}"
    ;;
    restart)
    $0 stop
    $0 start
    ;;
    esac
    exit 0

  5. Make the above script executable:
    sudo chmod +x /etc/init.d/vncserver
  6. Make this script into a system service by adding this script to the runtime scripts invoked at bootup time.
    sudo update-rc.d vncserver defaults
  7. To start the service without rebooting the SERVER:
    sudo /etc/init.d/vncserver start
  8. If you made a mistake/typo in the script, you can undo the creation of the system-wide service (step 5) by running the command:
    sudo update-rc.d -f vncserver remove You may then correct your mistake and then repeat steps 5 and 6.
  9. Well done!  You may now connect to your Ubuntu PC SERVER via remote desktop by simply powering on the SERVER and giving it enough time to bootup and run all of its system-wide services.

References

About these ads

20 comments on “How to install VNC server on an Ubuntu PC and remote connect to it from a Windows PC

  1. [...] to install a VNC server on Ubuntu 10.04 and how to make it run after boot. The article is based on this post by the seeker’s [...]

  2. Hi,

    I’ve read your tutorial and tryed it (with ubuntu 10.10). I’d like to add one precision : you have to give execution permission to xinitrc file

    chmod 755 /etc/X11/xinit/xinitrc

    But I have one question : when I’m typing “sud” in an application (konsole, xterm, firefox, …), all windows are reduced in the bar. Do you know where this problem could come from ? It’s really annonying as I can’t run sudo command !

    • You fix the all windows minimizing when pressing the ‘d’ key by doing the following steps:

      In Gnome, on the top bar go to System -> Preferences -> Keyboard Shortcuts

      Scroll down a bit and you should find an action on the left side that reads “Hide all normal windows and set focus to the desktop”. If I had to guess, this would probably say just ‘d’ in your case. This is the reason why your windows are minimizing!

      Click on the d and then you can put in a new keyboard combination. I just used alt+d and all of my problems went away.

      Hope this helps! I just had this problem tonight and that got it working for me!

      -Tom

  3. dragos says:

    Thanks for the post. I am a newbie in Linux, got a Ubuntu 10.10 up and running, I could access it in my local network with vnc but I can’t make it run from the internet.
    Opened ports in the router, connected using putty ssh with forwarding 5900 but I cant get it to work…Any advice would be appreciated. thanks

  4. izghitu says:

    thanks a lot for the post

  5. [...] to the internet community along with the help of this website until i tested and proved it works (theseekersquill) . Hope guys will enjoy it while following the steps [...]

  6. oaeide says:

    Hi, I followed this guide, and it works, however, I can’t open gnome applications like system monitor, or disk utility anymore, as they shut down immidiately. Does anyone have any tips?

    • Michael says:

      >Hi, I followed this guide, and it works, however, >I can’t open gnome applications like system >monitor, or disk utility anymore, as they shut >down immidiately. Does anyone have any tips?

      Was there a response or fix for this issue?

  7. ruwan says:

    Thanks, it works !!!

  8. Michael says:

    Well, I found a pretty easy work around on the Disk Utility and I assume Gnome problem.

    First, I must say, nothing worked well with Ubuntu 10.10 I gave up after VNC sessions crashed 10 minutes after starting and several other problems related to X and vnc – I went back to Ubuntu 10.04 as Ubuntu 10.10 is not ready for prime time, or my time right now.

    Anyway, if you follow the guide through step 4 just before the “On the Windows PC” and stop, then disable the Remote Desktop by unchecking it (system>Preferences>Startup Applications) from your Startup group in your login (though I am not sure if this is necessary, but I did).

    Next you are ready to connect as soon as you SSH in (Putty) and login as yourself, issue the command to start the server: vncserver :1 -depth 16 -geometry 1200×768

    Then Start your TightVNC or whichever client VNC you like to the x.x.x.x:1 and Gnome etc. will work.

    Michael

  9. [...] Ubuntu Remote Desktop [...]

  10. Todd says:

    I have a question. For some reason, when I run a program remotely, it does not show up on the local desktop, but it is still running in the background. The opposite is true as well, if I start a program locally (the display connected the the server) it does not show up remotely. Is there a setting to allow viewing and controlling in both places? Thanks,

    Todd

  11. Paolo says:

    Tnx a lot! I’ve solved my problems with the screen resolution following your guide!
    Before I’ve had always problems with screen using the “remote desktop” utility present in Ubuntu.

    Greeting from Italy!

  12. [...] have a question. For some reason, when I run a program Remotely, it does not show up on the local desktop, but it is still running in the background. The [...]

  13. premiumpress says:

    Hello there! This blog post couldn’t be written much better! Going through this article reminds me of my previous roommate! He continually kept preaching about this. I most certainly will send this information to him. Fairly certain he will have a very good read. Thank you for sharing!

  14. I am not sure where you are getting your info, however great topic.
    I must spend a while finding out more or working out more.
    Thanks for excellent information I used to be in
    search of this info for my mission.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s