Difference between revisions of "Install VNC server on Ubuntu Server 12.04"

From Amahi Wiki
Jump to: navigation, search
m (Added tips and tricks for starting super user level graphical programs)
Line 354: Line 354:
 
* To start the VNC just type the following into a terminal (using something like [[Key-based SSH Logins With Putty|Putty]]. This will start a new VNC session.
 
* To start the VNC just type the following into a terminal (using something like [[Key-based SSH Logins With Putty|Putty]]. This will start a new VNC session.
 
{{Code|vncserver}}
 
{{Code|vncserver}}
 +
 +
=Tips and Tricks =
 +
 +
VNC does not respect the normal rules of elevating the current user through the use of entering the admin password. The only way to run many graphical programs that require the super user is to open a command line terminal within the VNC session and start the program with the "sudo" command. Two programs that may come in handy that work in this fashion are gparted and Synaptic Package Manager.
 +
 +
To start gparted:
 +
 +
In a VNC terminal window type:
 +
 +
{{Code|
 +
Code = sudo gparted
 +
}}
 +
 +
To start Synaptic Package Manager:
 +
 +
In a VNC terminal window type:
 +
 +
{{Code|
 +
Code = sudo synaptic
 +
}}

Revision as of 15:39, 14 August 2012

NOTE: there is now a one-click VNC App


Warning.png WARNING
This is recommended only for advanced users, proceed with caution.



Method 1

Install vncServer in Ububtu 12.04 server to create a virtual desktop on another computer

These are the instructions for installing vncserver on Ubuntu 12.04 server edition. They may also work on Desktop, but I haven't tested them on it.

First install ubuntu 12.04 server

Install Amahi using the instructions provided elsewhere on the wiki.

After reboot go to your HDA and login, then go to apps and install OpenSSH and webmin using the links in your HDA.

Reboot

bash code
​sudo reboot now -h​


From here on I used vim but you can use any editor you are comfortable with just replace vim with your choice.

A quick and short tutorial on vim:

Move the cursor to where you want to edit then press i Edit as needed, when finished press esc then :wq to save your changes If you make a mistake press :q! you exit without saving changes, then start again.

A cheat sheet for vim commands can be found here:

http://www.tuxfiles.org/linuxhelp/vimcheat.html

Now go to another machine, I used windows 7, and download putty.

http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html)

From here on it will be all copy and paste in putty. (makes it easy)

Start putty

In Host Name (or IP address) enter the static ip address of your server, you can find it in your control panel on Amahi.org. For example: 192.168.1.55

DO NOT enter http://

Leave the Port at 22

PUTTY1.gif

If you want you can save it for easier later use by adding a name in Saved Sessions and clicking Save

Now click Yes

A terminal will open and another window asking you to confirm the server click okay

PUTTY2.gif

Enter your ubuntu username and password when asked

PUTTY3.jpg

You will be connected to your server.

all the following commands can be copied and pasted into putty with a simple right click.

Copy and paste

bash code
​sudo apt-get update​


when complete

bash code
​sudo aptitude safe-upgrade​


reboot server type

bash code
​sudo reboot now -h​


A: Install Gnome basic desktop.

log in with putty again from your windows machine.

I installed the server version of Ubuntu, so to be able to have a desk top when I log into vnc I need to install a few things in Ubuntu.

First off we need to install the Gnome components for our virtual desktop. Type or copy and paste:

bash code
​sudo apt-get install gnome-core​


when prompted type Y and then press Enter. This will install the gnome desktop components.

Reboot

bash code
​sudo reboot now -h​


To keep the desktop and login window from opening in Ubuntu everytime it starts we want to mask out the few lines which start the service.

bash code
​sudo vim /etc/init/gdm.conf​


The first few lines of the script should look like this once you've edited it:

bash code
​# gdm - GNOME Display Manager # # The display manager service manages the X servers running on the # system, providing login and auto-login services description "GNOME Display Manager" author "William Jon McCann <mccann@jhu.edu>" #start on ((filesystem # and runlevel [!06] # and started dbus # and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1 # or stopped udev-fallback-graphics)) # or runlevel PREVLEVEL=S) stop on runlevel [016] emits login-session-start​


esc :wq to save the changes or :q! to start over. Now the desktop and login won't start in Ubuntu.

NOTE: This only installs a basic desktop, if you want to be able to use programs from your virtual desktop, network manager, media players, office, etc, they will need to be installed after vnc server is installed.

Reboot

bash code
​sudo reboot now -h​


B: We need to install VNC server to be able to interact with the gnome components for the desktop.

bash code
​sudo apt-get install vnc4server​


When prompted type Y and press Enter. This will install VNC Server which is required for running a virtual desktop on another machine.

Next type:

bash code
​vncserver​


You'll then be prompted to create and verify a new password.

We now need to kill the session we just created and make change the startup script for VNCServer to make it work properly.

So, type the following command to kill the session:

bash code
​vncserver -kill :1​


Now type the following command to open up the file we need to edit:

bash code
​sudo vim .vnc/xstartup​


Change it to look like this:

bash code
​#!/bin/sh # Uncomment the following two lines for normal desktop: unset SESSION_MANAGER #exec /etc/X11/xinit/xinitrc gnome-session --session=gnome-classic & [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & #x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" & #x-window-manager &​


When you're done editing the file press the Esc key once and type :wq

This should save the changes and bring you back to the command line. If you make a mistake editing the file then issue :q! instead of :wq to abort your changes.

Next type the following command to create the VNC Session once more:

bash code
​vncserver -geometry 1680x1050​


where 1280x1024 is the resolution of your DESKTOP COMPUTER.

Download and install TightVNC onto your desktop computer.

http://www.tightvnc.com/download.html

When you launch it type your hda server name followed by a colon and the number 1 (this is the name you gave it when you installed Ubuntu)for example: Ubuntu-1204:1

Vnc.jpg

Or use it's static ip address and :1 eg: 192.168.1.55:1 in the VNCServer box.

Vnc1.jpg

Then click Connect, enter the password you created when you typed after installing vncserver.

Vnc2.jpg

You now see the desktop screen.

Vnc3.jpg

________________________

C: Write a script to launch VNC

A script is basically a file containing a list of commands which will be executed each time you run it. I put all my scripts in a directory below my "home" folder in a folder called scripts.

So, from a Putty session:

bash code
​cd /home/xxxx​


where xxxx is your Ubuntu username. This command switches us into that directory.

Next we'll create a folder called MyScripts below your home folder. So type:

bash code
​mkdir scripts​


Switch into the folder we've just created type:

bash code
​cd scripts​


Next type:

bash code
​vim StartVNC.sh​


This will create a new file called StartVNC.sh and open it for editing.

Press the i key once and copy and paste the following contents:

bash code
​#!/bin/sh echo "JOB RUN AT $(date)" echo "============================" echo "" /usr/bin/vncserver -geometry 1680x1050​


NOTE: change the 1680x1050 to match the screen resolution of your Desktop computer

Press the ESC key once and type :wq and press Enter to save.

Next we need to make the file executable so, assuming you called your script StartVNC.sh then you'd type:

bash code
​chmod a+x StartVNC.sh​


Test the script by typing the following:

bash code
​vncserver -kill :1​


To make sure vncserver isn't running, then:

bash code
​./StartVNC.sh​


A new vnc session should start.

D: Create a cron job in webmin to run the script on boot

Stop vncserver

bash code
​vncserver -kill :1​


Now open your browser and go to your HDA and click on the webmin app you already installed, click continue to this website at the cert warning.

Webmin1.jpg

Enter user and password as required.

Webmin2.jpg


Within Webmin click on System and then Scheduled Cron Jobs in the left column. Then click the Create a new scheduled cron job option at the top of the screen that opens.

Click the button next to the Execute cron job as and choose the username you created when you installed Ubuntu. Hint: your username appears in a Putty/Terminal session prompt. eg. yourusernameappearshere@Myhdaserver.

Type or paste the name of your script including the full path

bash code
​/home/xxxx/scripts/StartVNC.sh >/dev/null​


into the Command box, replacing xxxx with your own usernam. The ">/dev/null" parameter will discard any output the script may produce.

Enter a suitable description in the Description field.

In the When to Execute - Simple schedule drop-down list choose When system boots then click the Create button at the bottom of the screen.

It should look like this:

Webmin3.jpg

First test that you've set the job up correctly within Webmin. You can do this by clicking on the job you've just created from the long list of cron jobs (not checking the box but clicking on the name). In the new window that opens click the Run Now button at the bottom of the screen. You should see a message similar to the one you saw when you tested it from a Putty/Terminal session.

Now let's check the script works on boot. So from the System -> Bootup and Shutdown menu within Webmin scroll down to the bottom of the screen and click the Reboot System button. Alternatively type

bash code
​sudo reboot now -h​


in a Putty/Terminal session.

After reboot go to your Windows machin and open Tight VNC Viewer and connect to your ubuntu virtual desktop. VNC Server now starts automatically on boot.

That's it you should now have vnc server start on boot and a virtual desktop for your server on another machine.

Most of this information was obtained from: www.havetheknowhow.com.


Alternate Method

This is just what I found on how to install a VNC for Ubuntu 12.04LTS after figuring out that TigerVNC (the above methods) do not work for Ubuntu. The method is copied from here. This will result in the gnome GUI, not Unity.

  • First we need to update our repositories and install gnome.
bash code
​sudo apt-get update sudo apt-get install gnome-core gnome-session-fallback​


  • Next we install VNC4Server. Follow the instructions.
bash code
​sudo apt-get install vnc4server​


  • We need to test the VNC, and then close the session. In the process we are prompted for a password to use everytime we try to connect using our VNC client.
bash code
​vncserver vncserver -kill :1​


  • We open the startup file that we need to edit to make gnome show up in the VNC, and not just a terminal:
bash code
​cp .vnc/xstartup .vnc/xstartup.bak nano .vnc/xstartup​


  • We edit the file to uncomment the second line, and add "gnome-session -session=gnome-classic &". So it will look like this:
Text
​#!/bin/sh # Uncomment the following two lines for normal desktop: unset SESSION_MANAGER #exec /etc/X11/xinit/xinitrc gnome-session –session=gnome-classic & [ -x /etc/vnc/xstartup ] && exec /etc/vnc/xstartup [ -r $HOME/.Xresources ] && xrdb $HOME/.Xresources xsetroot -solid grey vncconfig -iconic & #x-terminal-emulator -geometry 80×24+10+10 -ls -title “$VNCDESKTOP Desktop” & #x-window-manager &​
  • And finally we quit nano and save the file.
     ctrl + x
     y (for confirmation that yes, we do want the file to be overwritten with the new information)}}
  • To start the VNC just type the following into a terminal (using something like Putty. This will start a new VNC session.
bash code
​vncserver​


Tips and Tricks

VNC does not respect the normal rules of elevating the current user through the use of entering the admin password. The only way to run many graphical programs that require the super user is to open a command line terminal within the VNC session and start the program with the "sudo" command. Two programs that may come in handy that work in this fashion are gparted and Synaptic Package Manager.

To start gparted:

In a VNC terminal window type:

bash code
​sudo gparted​


To start Synaptic Package Manager:

In a VNC terminal window type:

bash code
​sudo synaptic​