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

From Amahi Wiki
Jump to: navigation, search
Line 11: Line 11:
 
Reboot
 
Reboot
  
{{Code|sudo reboot now -h}}
+
{{Code|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.
 
From here on I used vim but you can use any editor you are comfortable with just replace vim with your choice.
Line 51: Line 51:
 
Copy and paste   
 
Copy and paste   
  
[code]sudo apt-get update}}
+
{{Code|Code = sudo apt-get update}}
  
 
when complete
 
when complete
  
{{Code|sudo aptitude safe-upgrade}}
+
{{Code|Code = sudo aptitude safe-upgrade}}
  
 
reboot server type  
 
reboot server type  
  
{{Code|sudo reboot now -h}}
+
{{Code|Code = sudo reboot now -h}}
 +
 
 
A: Install Gnome basic desktop.  
 
A: Install Gnome basic desktop.  
  
Line 68: Line 69:
 
First off we need to install the Gnome components for our virtual desktop. Type or copy and paste:
 
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|Code = sudo apt-get install gnome-core}}
  
 
when prompted type Y and then press Enter. This will install the gnome desktop components.
 
when prompted type Y and then press Enter. This will install the gnome desktop components.
Line 74: Line 75:
 
Reboot
 
Reboot
  
{{Code|sudo reboot now -h}}
+
{{Code|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.
 
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|Code = sudo vim /etc/init/gdm.conf}}
  
 
The first few lines of the script should look like this once you've edited it:
 
The first few lines of the script should look like this once you've edited it:
{{Code|
+
{{Code|Code =
 +
 
 
# gdm - GNOME Display Manager
 
# gdm - GNOME Display Manager
 
#
 
#
Line 109: Line 111:
 
Reboot
 
Reboot
  
{{Code|sudo reboot now -h}}
+
{{Code|Code = sudo reboot now -h}}
  
 
B: We need to install VNC server to be able to interact with the gnome components for the desktop.
 
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|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.
 
When prompted type Y and press Enter. This will install VNC Server which is required for running a virtual desktop on another machine.
Line 119: Line 121:
 
Next type:
 
Next type:
  
{{Code|vncserver}}
+
{{Code|Code = vncserver}}
  
 
You'll then be prompted to create and verify a new password.  
 
You'll then be prompted to create and verify a new password.  
Line 127: Line 129:
 
So, type the following command to kill the session:
 
So, type the following command to kill the session:
  
{{Code|vncserver -kill :1}}
+
{{Code|Code = vncserver -kill :1}}
  
 
Now type the following command to open up the file we need to edit:
 
Now type the following command to open up the file we need to edit:
  
{{Code|sudo vim .vnc/xstartup}}
+
{{Code|Code = sudo vim .vnc/xstartup}}
  
 
Change it to look like this:
 
Change it to look like this:
  
{{Code|
+
{{Code|Code =
 +
 
 
#!/bin/sh
 
#!/bin/sh
  
Line 157: Line 160:
 
Next type the following command to create the VNC Session once more:
 
Next type the following command to create the VNC Session once more:
  
{{Code|vncserver -geometry 1680x1050}}
+
{{Code|Code = vncserver -geometry 1680x1050}}
  
 
where 1280x1024 is the resolution of your DESKTOP COMPUTER.
 
where 1280x1024 is the resolution of your DESKTOP COMPUTER.
Line 191: Line 194:
 
So, from a Putty session:
 
So, from a Putty session:
  
{{Code|cd /home/xxxx}}
+
{{Code|Code = cd /home/xxxx}}
  
 
where xxxx is your Ubuntu username. This command switches us into that directory.
 
where xxxx is your Ubuntu username. This command switches us into that directory.
Line 197: Line 200:
 
Next we'll create a folder called MyScripts below your home folder. So type:
 
Next we'll create a folder called MyScripts below your home folder. So type:
  
{{Code|mkdir scripts}}
+
{{Code|Code = mkdir scripts}}
  
 
Switch into the folder we've just created type:
 
Switch into the folder we've just created type:
  
{{Code|cd scripts}}
+
{{Code|Code = cd scripts}}
  
 
Next type:
 
Next type:
  
{{Code|vim StartVNC.sh}}
+
{{Code|Code = vim StartVNC.sh}}
  
 
This will create a new file called StartVNC.sh and open it for editing.
 
This will create a new file called StartVNC.sh and open it for editing.
Line 211: Line 214:
 
Press the i key once and copy and paste the following contents:
 
Press the i key once and copy and paste the following contents:
  
{{Code|
+
{{Code|Code =
 +
 
 
#!/bin/sh
 
#!/bin/sh
 
echo "JOB RUN AT $(date)"
 
echo "JOB RUN AT $(date)"
Line 226: Line 230:
 
Next we need to make the file executable so, assuming you called your script StartVNC.sh then you'd type:
 
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|Code = chmod a+x StartVNC.sh}}
  
 
Test the script by typing the following:
 
Test the script by typing the following:
  
{{Code|vncserver -kill :1}}
+
{{Code|Code = vncserver -kill :1}}
  
 
To make sure vncserver isn't running, then:
 
To make sure vncserver isn't running, then:
  
{{Code|./StartVNC.sh}}
+
{{Code|Code = ./StartVNC.sh}}
  
 
A new vnc session should start.
 
A new vnc session should start.
Line 242: Line 246:
 
Stop vncserver
 
Stop vncserver
  
{{Code|vncserver -kill :1}}
+
{{Code|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.
 
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.
Line 259: Line 263:
 
Type or paste the name of your script including the full path  
 
Type or paste the name of your script including the full path  
  
{{Code|/home/xxxx/scripts/StartVNC.sh >/dev/null}}
+
{{Code|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.
 
into the Command box, replacing xxxx with your own usernam. The ">/dev/null" parameter will discard any output the script may produce.
Line 275: Line 279:
 
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  
 
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|Code = sudo reboot now -h}}
  
 
in a Putty/Terminal session.
 
in a Putty/Terminal session.

Revision as of 23:53, 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

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


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

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.

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.