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

From Amahi Wiki
Jump to: navigation, search
Line 244: Line 244:
 
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.
 
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.
  
Picture webmin1
+
[[File:webmin1.jpg]]
  
 
Enter user and password as required.  
 
Enter user and password as required.  
  
Picture webmin2
+
[[File:webmin2.jpg]]
  
  
Line 267: Line 267:
 
It should look like this:
 
It should look like this:
  
Picture webmin4
+
[[File: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.
 
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.

Revision as of 23:32, 1 July 2012

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

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


Now go to another machine, I used windows 7, and install putty. (download here 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. 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

[code]sudo apt-get update[/code]

when complete

[code]sudo aptitude safe-upgrade[/code]

reboot server type

[code]sudo reboot now -h[/code]

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:

[code]sudo apt-get install gnome-core[/code]

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

Reboot

[code]sudo reboot now -h[/code]

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.

[code]sudo vim /etc/init/gdm.conf[/code]

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

  1. gdm - GNOME Display Manager
  2. The display manager service manages the X servers running on the
  3. system, providing login and auto-login services

description "GNOME Display Manager" author "William Jon McCann <mccann@jhu.edu>"

  1. start on ((filesystem
  2. and runlevel [!06]
  3. and started dbus
  4. and (drm-device-added card0 PRIMARY_DEVICE_FOR_DISPLAY=1
  5. or stopped udev-fallback-graphics))
  6. or runlevel PREVLEVEL=S)

stop on runlevel [016]

emits login-session-start

____________________________________________________________________[/code]

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

[code]sudo reboot now -h[/code]

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

[code]sudo apt-get install vnc4server[/code]

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:

[code]vncserver[/code]

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:

[code]vncserver -kill :1[/code]

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

[code]sudo vim .vnc/xstartup[/code]

Change it to look like this:

[code]____________________________________________________________________________

  1. !/bin/sh
  1. Uncomment the following two lines for normal desktop:

unset SESSION_MANAGER

  1. 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 &

  1. x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
  2. x-window-manager &

_____________________________________________________________________________ [/code]

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:

[code]vncserver -geometry 1680x1050[/code]

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:

[code]cd /home/xxxx[/code]

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:

[code]mkdir scripts[/code]

Switch into the folder we've just created type:

[code]cd scripts[/code]

Next type:

[code]vim StartVNC.sh[/code]

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:

[code]__________________________________________________________

  1. !/bin/sh

echo "JOB RUN AT $(date)" echo "============================" echo "" /usr/bin/vncserver -geometry 1680x1050

______________________________________________________________[/code]

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:

[code]chmod a+x StartVNC.sh[/code]

Test the script by typing the following:

[code]vncserver -kill :1[/code]

To make sure vncserver isn't running, then:

[code]./StartVNC.sh[/code]

A new vnc session should start.

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

Stop vncserver

[code]vncserver -kill :1[/code]

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

[code]/home/xxxx/scripts/StartVNC.sh >/dev/null[/code]

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

[code]sudo reboot now -h[/code]

in a Putty/Terminal session.

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.