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

From Amahi Wiki
Jump to: navigation, search
Line 10: Line 10:
  
 
Reboot
 
Reboot
 +
 +
{{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 49: 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 67: Line 68:
 
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 73: Line 74:
 
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|
 
# gdm - GNOME Display Manager
 
# gdm - GNOME Display Manager
 
#
 
#
Line 100: Line 101:
 
emits login-session-start
 
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.
 
esc :wq to save the changes or :q! to start over. Now the desktop and login won't start in Ubuntu.
Line 108: Line 109:
 
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 118: Line 119:
 
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 126: Line 127:
 
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|
 
#!/bin/sh
 
#!/bin/sh
  
Line 148: Line 149:
 
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
 
#x-terminal-emulator -geometry 1280x1024+10+10 -ls -title "$VNCDESKTOP Desktop" &
 
#x-window-manager &
 
#x-window-manager &
_____________________________________________________________________________
+
}}
[/code]
 
  
 
When you're done editing the file press the Esc key once and type :wq
 
When you're done editing the file press the Esc key once and type :wq
Line 157: Line 157:
 
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 185: Line 185:
 
C: Write a script to launch VNC
 
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.
+
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:
 
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 195: Line 197:
 
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 209: Line 211:
 
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|
 
#!/bin/sh
 
#!/bin/sh
 
echo "JOB RUN AT $(date)"
 
echo "JOB RUN AT $(date)"
Line 216: Line 218:
 
/usr/bin/vncserver -geometry 1680x1050
 
/usr/bin/vncserver -geometry 1680x1050
  
______________________________________________________________[/code]
+
}}
  
 
NOTE: change the 1680x1050 to match the screen resolution of your Desktop computer
 
NOTE: change the 1680x1050 to match the screen resolution of your Desktop computer
Line 224: Line 226:
 
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 240: Line 242:
 
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 257: Line 259:
 
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 273: Line 275:
 
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:46, 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

[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
{{{1}}}


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
{{{1}}}


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
{{{1}}}


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.