Setting Up VNC

While the Raspberry Pi does provide a superb picture over hdmi, there are a lot of scenarios where one might not need a display, and connecting remotely via VNC will suffice.  For instance, any programming could be done remotely, while still having access to the physical hardware.  It's also particularly useful when the TV is in use and getting it back to "play on" isn't an option.

EDIT 25/04/2012: Ive now identified how to enable SSH automatically - see below (thanks Abishur!!)

EDIT 20/08/2012: I've worked out how to start VNC automatically on bootup - see my other post here http://myraspberrypiexperience.blogspot.co.uk/2012/08/start-vnc-automatically.html

Pre-requisites
As a bit of background, I'm using the latest Debian image (19/04/2012) and I'm connecting from my Windows 7 laptop.  To connect I've installed UltraVNC on my laptop - you can download a free copy from here:
UltraVNC Downloads Page

Now, once  the VNC server is up and running on the Pi you can VNC from your laptop into your Pi without doing anything on the Pi first.  If you've just turned it on however, you'll need to first start the VNC server on the Pi.  And if you're using this as a truly headless box, that can be a little difficult.  To get around this I've used the PuTTY SSH client, which you can download here:
PuTTY Downloads Page

The last thing you need to know is the IP Address.  If you've configured your Pi with a static IP Address, that's great.  If you have access to your router to look this up that's fine too.  You might however be in a situation where you have no way to look up the IP Address (like me) - for this I needed a utility to scan the network for all machines.  For this I used:
Advanced IP Scanner
This will scan your network listing all devices it can find.  Simply look through the list of devices and find your Rashberry Pi. It'll have a fairly obvious name, like "RaspberryPi".

Alternatively, if you have access to your wireless router, you might be able to connect to this and see a list of all devices that have connected to it, including your Raspberry Pi.  As each wireless router differs, I'll leave this up to you to figure out :-)

Starting SSH on the Pi
First off - what is SSH?  It's a process that can be run in Linux that will allow you to access your Raspberry Pi remotely.  You'll be able to run anything that you would normally run from the command line on your Raspberry Pi, remotely from an SSH client - i.e. Putty.  #

I've found that the latest Debian image doesn't come with SSH enabled by default.  If you have a monitor and keyboard attached, once you've logged in you can start SSH by typing sudo /etc/init.d/ssh start as shown below:



Now, the idea of SSH is that we can connect remotely without a display, so you don't necessarily want to have to do this every time you boot up. 



EDIT 28/01/2013: There are two approaches to enabling SSH.


First option
For older images like Debian there is a file in place that can be used to do this - boot_enable_ssh.rc.  This file is on the boot partition of the SD card - i.e. the partition that can be read by Windows.  So - put the card into your PC card reader and open it up:


Now rename boot_enable_ssh.rc to boot.rc:
 


Once you've done this put the card back into the Pi and boot up - SSH will now be automatically enabled.
 


Second option
If you're using a newer distro like Raspbian Wheezy, when you first boot up the image you'll be taken to a config screen. From here you'll be able to enable SSH (along with a number of other useful options!).



Connecting via SSH
As mentioned above, to be able to connect into the Pi using VNC you first need to start the VNC server, and without a display connected you need to start this remotely.  SSH provides this mechanism.  To start with, we take our SSH Client - PuTTY.  Once you've downloaded it, simply launch it - it's a standalone exe - you'll be presented with this screen:

Simply type in Raspberry Pi IP Address in the Host Name field that you found earlier and click open.  Once Putty has connected to the SSH process running on the Pi, a terminal window will pop up and you'll be prompted with a login.  

I still have my UN & PW set to pi and raspberry, so just typed that in.  Once logged in I'm taken to the standard terminal prompt.  From here you can run pretty much any command you want on the Raspberry Pi.

Setting up VNC Server via SSH
Now that you're connected, you need to start the VNC server.  If this is the first time you're doing this, you'll also need to install VNC first.  I've assumed you'll have internet access as this will be required to install this.  To do this, run the following command:
sudo apt-get install tightvncserver

As mentioned above, the Putty SSH Client lets you run commands on your Pi directly, so by doing this you're installing a VNC application on your Pi.

NOTE: during the install you'll be prompted to install without verification - type y here. 

Once installed, you'll need to start the VNC server.  The command I've used here is vncserver :1 -geometry 1280x800 -depth 16 -pixelformat rgb565:

This will start the VNC server process on the Pi.  What this means is that it will start a virtual X session (a virtual instance of the Raspberry Pi GUI) on your Pi, in a very similar way to when you run startx when your Pi is connected to a display.  When you VNC into your Pi you will be connecting to this X session.

So - the important port of this command is :1.  This defines the port that the VNC process will be started on - you can make this whatever you want, but will need to remember it to ensure you connect to the right port.  You'll see more details on this below.  As for the resolution (-geometry) this will be the resolution that the X session will run under - you can make this pretty much whatever you want 

The first time you launch VNCServer you'll be prompted for a password - you'll need this to connect in using VNC.

You'll also be asked for a view-only password (optional).  When providing the password via VNC the remote use will only have read-only access to the Raspberry Pi:


Connecting via UltraVNC 
Once VNC server has been started the only thing left to do is connect.  Start up UltraVNC, type in the IP Address (or machine name) with a port of 1 and connect.  
NOTE:  This port is the port you used when starting the VNC process above:

And that's it - connected!


EDIT 06/05/2012: I've found out there are two potential desktops you might see, and this is determined by the user that launches vncserver (or startx for that matter).  Using sudo will give you the LXDE desktop above.  Launching it without sudo will give the intended Raspberry Pi desktop as shown below.
 


'Linux > RaspberryPi' 카테고리의 다른 글

Raspberry Pi – Enabling Telnet  (0) 2015.06.29
Raspberry Pi에서 Java 설치하기!  (0) 2015.06.25
시작시 Auto running programs  (0) 2015.01.03
(cpp)wiringpi활용  (0) 2015.01.03
(python)GPIO 끄기: GPIO cleanup()  (0) 2015.01.03

+ Recent posts