Markus Blog What's going on Internet?

2Aug/0955

Installing VNC Remote Desktop on Ubuntu Linux VPS


I have a linux Ubuntu 8.10 VPS that I would like to have GUI and use it as remote desktop pc just like what we can do with Windows XP. Here are the steps that I run.

1. Most of the VPS that delivered by VPS hosting provider is minimal setup of linux, it means that most of the time it only have SSH server installed and the other services such as HTTP server, FTP server, Mail server must be installed by our self. The default setup of VPS linux also doesn’t have window manager (GUI) hence we must install it first:

sudo apt-get install ubuntu-desktop

2. Configure the Gnome Desktop Manager and XServer

sudo /etc/init.d/gdm start
sudo dpkg-reconfigure xserver-xorg

3. After we installed a window manager, next step is to install the remote desktop server, for linux we use TightVNC

sudo apt-get install tightvncserver

4. Next we need to configure the remote desktop server and create a password to access the VPS via its GUI. This command will start the server, you will be asked for a password, this password will be used as authentication when you connect to the VPS, make sure you have a strong password.

vncserver :1 -geometry 1024x768 -depth 16 -pixelformat rgb565

5. Now, if you execute command

ps aux

You should see an Xtightvnc process:

Xtightvnc :1 -desktop X –auth

This means the setting is OK and VNC server is running fine.

6. The default VNC server doesn’t use Gnome window manager as default, to run Gnome as default we must do some changes on the configuration file.

sudo nano ~/.vnc/xstartup

Comment "x-window-manager" and add this on the end of file:

gnome-session &

so it will look like this:

#!/bin/sh
 
xrdb $HOME/.Xresources
xsetroot -solid grey
x-terminal-emulator -geometry 80x24+10+10 -ls -title "$VNCDESKTOP Desktop" &
#x-window-manager &
gnome-session &

7. Next, do a reboot. Usually a reboot is not needed, but just to make sure you can do it.

sudo reboot

8. Start the VNC server:

vncserver :1 -geometry 1024x768 -depth 16 -pixelformat rgb565

9. Download Tight VNC client here: http://www.tightvnc.com/download.html

10. After you install it, run the VNC client and insert your VPS IP address and VNC server number on the VNC Server field and click on “Connect”. In this tutorial the VNC server number is :1, so you must fill in :1

VNC client login

You will be asked for a password to access the remote desktop, this password is the one you set on step 4.

Bookmark and Share
Comments (55) Trackbacks (7)
  1. Yes, I copy the command that you gave me. but don’t remove all the files and dir of Ubuntu desktop.

    I want to get back to the initial configuration, any idea how to do that?

  2. Im sorry, but a person who does this 1st time wont understand a thing!

    • which part you don’t understand? i thought it’s pretty clear as i already give a step-by-step tutorial.

      • I got this right every time. I added this to my collection of reference material. Every time I buy a new VPS this is one of my guides I use as a reference.

  3. @Dave – Your wrong, the first time I have ever had a VPS and I got it all, I am very tech savvy though.

    I would like to thank you for this tutorial, it is exactly what I needed and I am so happy, guys if your getting an error saying it couldnt find the package then use this command;

    sudo apt-get update

    and retry the steps above.

    • It didn’t work for me the first time, the ubuntu desktop install failed. I changed my OS to the latest version of Ubuntu on the VPS (10.x) and it worked like a charm! I’ve been all over hell and back trying to figure out how to get this working. The key was I didn’t have a desktop installed, but not being able to remote in I wouldn’t have known that until I read your post and realized they (the host) probably omitted installing that.

      You rock!

  4. thanks all for this tutorial !!!

  5. THANKS!!!!!!!!!!!!!!!!!!!!!!!!!!!

  6. I think that Dave did not understand how to get connected to the root acces. Well Dave , you have to use PuTTY for that and from there run these commands….

  7. This is a great tutorial.

    It is bookmarked as a reference. I have used it a number of times. Well done!

  8. This a good guide overal but the “ubuntu-desktop” default package is way too bloated for a VPS. You should write a guide for a minimal install of ubuntu instead.

  9. Wow this was a great guide. It worked perfectly for me, and I am a first time VPS user. I have a linode account with Ubuntu on there. I learned all the command line stuff but wanted a “remote desktop”. Thank you!

  10. Thanks alot mate, your a life saver!

    This problem had had me against the ropes for two days. i had purchased a vps that only provided linux due it being a third of the cost of a windows vps and then my nightmare started. (i had never used linux before so all i knew is what some websites on google told me.

    I wanted to use the gnome desktop through ssh, but what i didn’t understand was that “x server” (the thing that runs the gnome desktop) wont start on a headless computer/server (a computer without a monitor) and most vps providers are very unlikely to have there vps’s hooked up to monitors (That would make them more expensive)

    So every time i tried “startx” (the command to start the gnome desktop) through ssh i wold get this error no matter what operating system i installed!

    X.Org X Server 1.7.7
    Release Date: 2010-05-04
    X Protocol Version 11, Revision 0
    Build Operating System: Linux 2.6.32.29-dsa-ia32 i686 Debian
    Current Operating System: Linux dot2635 2.6.32-238.19.1.el5.028stab092.2 #1 SMP Thu Jul 21 19:23:22 MSD 2011 i6
    86
    Kernel command line: quiet
    Build Date: 19 February 2011 02:37:36PM
    xorg-server 2:1.7.7-13 (Cyril Brulebois )
    Current version of pixman: 0.16.4
    Before reporting problems, check http://wiki.x.org
    to make sure that you have the latest version.
    Markers: (–) probed, (**) from config file, (==) default setting,
    (++) from command line, (!!) notice, (II) informational,
    (WW) warning, (EE) error, (NI) not implemented, (??) unknown.
    (==) Log file: “/var/log/Xorg.0.log”, Time: Fri Nov 25 10:31:55 2011
    (==) Using system config directory “/usr/share/X11/xorg.conf.d”

    Fatal server error:
    xf86OpenConsole: Cannot open /dev/tty0 (No such file or directory)

    Please consult the The X.Org Foundation support
    at http://wiki.x.org
    for help.
    Please also check the log file at “/var/log/Xorg.0.log” for additional information.

    giving up.
    xinit: No such file or directory (errno 2): unable to connect to X server
    xinit: No such process (errno 3): Server error.

    So anyone getting this error its because your trying to start the gnome desktop on a headless unit and it wont work. Anyway this fixes that and tells vnc to start the gnome desktop on connection and it will use your monitor as hardware.

    I had found many tutorials explaining this but they all missed something and didn’t lay it out in absolute layman’s terms for a complete newbie to linux like this guy did.

    Also i find whenever the ubuntu server has been shut down I have to use all three of these to get vnc to work everytime:

    sudo /etc/init.d/gdm start
    sudo dpkg-reconfigure xserver-xorg
    vncserver :1 -geometry 1024×768 -depth 16 -pixelformat rgb565

    Does the author know the exact command to add these three commands to auto start every time the computer boots?

    It would really help me out.

    Thanks again.

    • (1) Check where is vncserver located. Note the output, it will be needed later.
      $ which vncserver

      (2) Add the commands to autostart with crontab. When you are prompted for a password, enter your password. If that fails, try again with root’s password.
      $ sudo EDITOR=nano VISUAL=nano crontab -e
      [sudo] password for yourusername:

      In the text editor, add the following three lines to the end (or simply add them if the file is empty):

      @reboot /usr/bin/sudo /etc/init.d/gdm start
      @reboot /usr/bin/sudo /usr/sbin/dpkg-reconfigure xserver-xorg
      @reboot /path/to/vncserver :1 -geometry 1024×768 -depth 16 -pixelformat rgb565

      Finally, press Ctrl-O and then Ctrl-X to save your changes and exit from nano. On the next reboot, those commands will hopefully be executed.

      • Another thing I’d like to note is if what I said doesn’t work, execute this:
        $ sudo service cron start
        [sudo] password for yourusername:

        Then it should work.

  11. Really useful, thanks a lot.

    however I found that Ubuntu crashes a lot for me and when i try to use

    vncserver :3 -geometry 1024×768 -depth 16 -pixelformat rgb565

    Warning: (MYVPSSERVERNAME):3 is taken because of /tmp/.X3-lock
    Remove this file if there is no X server (MYVPSSERVERNAME):3
    A VNC server is already running as :3

    How do I get rid of this?

  12. How to automatic start the vnc server when reboot?
    Thanks


Leave a comment