Monday 25 March 2013

Keeping your Raspberry Pi updated with APT

Many Linux distributions including Raspbian for the Raspberry Pi come with the APT (Advanced Package Tool) package manager.

Access to this is often available as a GUI (Graphical User Interface), to help you update, upgrade and install new software packages on your computer. However if you can use APT via the command line you can save yourself a lot of time.

As a reminder to gain access to the command line, if you are logged directly into  the Raspberry Pi, you will need to load Terminal (click LXTerminal on the desktop). Alternatively Remotely logging into the Raspberry Pi via SSH gives you access to the command line.

Update

The first thing is to ensure you are using the latest versions of software. There are two stages to this. First you want to update the list of available software which is stored locally on your machine. You should always do this before starting any type of upgrade. To do this simply type:

sudo apt-get update




To then upgrade any software packages type:

sudo apt-get upgrade




and enter y when asked "Do you want to continue [Y/n]?"

Search

To search for a package that you would like to install type:

sudo apt-cache search packagename

i.e. for chromium




Install

To then install this package:

sudo apt-get install packagename

i.e. for chromium




Before running this command it is often worth running with the flag -s, which simulates the install. This enables you to check that the install is only installing what you expected:

sudo apt-get install -s packagename

i.e. for chromium




Remember to run the command without the -s flag to actually install the package once you have simulated it.

Uninstall

To remove a software package use:

sudo apt-get remove packagename

i.e. for chromium




Again its worth running this with the simulation flag -s first to check everything is as expected:

sudo apt-get remove -s packagename

i.e. for chromium




Kernel Update

Every so often the kernel or core program needs to be updated. This is not updated using the apt-get upgrade command, so you need to specifically tell it to update the kernel. This is done by typing:

sudo apt-get dist-upgrade



Hopefully this has given you a brief  introduction into the APT package manager and how to keep all your software packages up to date using the command line.

Monday 18 March 2013

Remotely Connect to a Raspberry Pi Desktop

I run my Raspberry Pi as a headless server. That is I don't have a television, mouse or keyboard attached to it. I log in remotely using SSH, or Secure Shell. Generally having access to the command line allows you to do most of what you need to do. However there are the odd times when you need access to a desktop on the Linux system.

So without having to connect my Raspberry Pi to a television and other peripherals how do I log into it remotely and have access to the desktop? The answer is by installing a VNC (Virtual Network Computing) server.

Installing a VNC Server on the Raspberry Pi

The first stage of this is you need  to install tightvncserver on the Raspberry Pi.

So once you have either remotely logged into your Raspberry Pi using SSH or, if you are logged in directly, you have opened LXTerminal, you need to install a VNC Server. Remember to update the list of available software packages first:

sudo apt-get update




Then install Tight VNC Server with:

sudo apt-get install tightvncserver



When asked 'Do you want to continue [y/n]?' press 'y'.

tightvncserver and probably a few other programs which tightvncserver is dependant on will install.

Now to configure this type:

tightvncserver



and you will be asked to type in a password. You will need to remember this for later!

Although it doesn't matter what you use for your password, tightvnc only uses the first 8 characters of your password. However if you type in more than 8 characters, that is fine, it will always ignore the characters you type after the first 8. The reason I say this is typing more than 8 characters produces the following warning.


If you are happy with the password you have chosen, then don't worry about this message. Personally - I just ignore it. :-)

You are then asked to verify your password, so simply retype your password.

The next question is 'Would you like to enter a view-only password (y/n)?'



I dont think this is necessary, so I enter 'n'. However if you think you would use it then press 'y'.

At this stage the VNC server is running. In subsequent reboots, to start the VNC server, now you have installed it you would have to type:

vncserver :1




Software to Enable Logging in Remotely

Once you have the VNC Server up and running you can now log into it from another machine.

If you don't have already, you will need a piece of software on the Mac or PC to log into this. I tend to use TightVNC Server on the PC and Chicken of the VNC on the Mac

TightVNC server can be downloaded from here.

http://www.tightvnc.com/

Chicken of the VNC for the Mac can be downloaded from here:

http://sourceforge.net/projects/cotvnc/

Using TightVNC

For TightVNC server you need to type the IP address of the Raspberry Pi into the text box. If you don't know what the IP address is you can follow these instructions to remotely find the IP address of your Raspberry Pi.




Click on connect and there you have it a GUI connection from another computer into your Raspberry Pi.


Using Chicken of the VNC

To use Chicken of the VNC, next to host type your IP Address followed by a colon and 5901 i.e.

192.168.1.66:5901

For those wondering what the 5901 signifies, this is specifying the port number. This number should be equal to 5900 + the number you typed in after vncserver. In our case we typed vncserver :1 so the port is 5900 + 1 which is 5901.

You will then need to type your password you entered when installing vncserver.

Finally click connect!


A window should appear showing your Raspberry Pi Desktop!






Monday 4 March 2013

Remotely Find Raspberry Pi IP Address

Recently I have two examples where I have needed to find devices on the local network and to establish their IP addresses.

The first of these was with my Raspberry Pi. I tend to run this as a headless server and normally SSH into it. This is impossible until I have established its IP address.

The second, and more recent, is with a new piece of hardware which the company I work for has developed. This runs embedded Linux and requires us to find its IP address in order to operate it.

For my Raspberry Pi my usual method of finding the IP address was to log into my router and check which devices were connected. As I regularly reformat my Raspberry Pi this is something I need to do often. I have always felt this was extremely cumbersome, and I am forever scrabbling around trying to find the log in details for my router.

When my colleagues needed to find our new device on the network at work, I explained my method of logging into the router and checking for the IP addresses. The company router however was not as friendly as my home one, and promptly spat out a list of 20 IP addresses. My colleagues checked these manually to find the new device. Needless to say this took time and is not a long term solution.

As an experiment I wrote a python script to ping all the IP addresses, and log the one we required. My fears were correct, that pinging 256 IP address was extremely slow!

Surely there must be a better way to do this? Initial Google searches showed other people stating they connected a TV and keyboard to the Raspberry Pi. They could then determine the IP address by typing ifconfig into the command line. What a pain!

Further searching revealed an excellent tool called nMap.

http://nmap.org

Even more appealing is the fact it works with Linux, Mac and Windows. I need to use it on all three.

I installed it on a Linux machine and ran the following from a command line:

sudo nmap -sn 192.168.1.0/24



Within seconds a list of all connected devices and their IP addresses appeared. Problem solved!

So how do you install nMap?

On a Linux system such as Raspbian it's simple. Just type the following into the command line:

sudo apt-get install nmap



Windows and Mac users need to run an installer which has the option of running a GUI (Graphical User Interface) version called Zenmap.

The installer can be found on the nmap website here:


Using nmap

I would recommend using the command line where possible. It really does save time and effort not having to run a GUI. Particularly if you are remotely logged in via SSH.

For Linux the command would be:

sudo nmap -sn 192.168.1.0/24




sudo is required to give you root permissions.

For Mac and PC just type:

nmap -sn 192.168.1.0/24




If you prefer a GUI version rather than using the command line then you are in luck! During installation onto the Apple Mac or PC you have the option to install Zenmap.

To use this load Zenmap and follow the three easy commands below.




  1. In the Target box type: 192.168.1.0/24
  2. Select Profile: Ping scan
  3. Click on: Scan
This should give you the same results you would obtain from the command line.

I hope you all find this as useful as I did!

Friday 1 March 2013

SSH into Raspberry Pi

I generally log into my Raspberry Pi via SSH, or Secure Shell to give it its full name. This allows command line access, to your Raspberry Pi, from another computer. Although it is possible to SSH into the Raspberry Pi from anywhere in the world, and I do, this post only covers SSH access over the local network. I will cover remote connection in a future blog post.

Although this does not give access to a GUI (Graphical User Interface), having access to the command line generally allows me to do 95% of what I need to do. The other 5% I could probably do through SSH, but sometimes you can't beat the comfort of a GUI. :-)

First of all you need to know the IP address of the Raspberry Pi you are wanting to log into. If you are unsure how to find this, then read my blog post explaining how you can do this remotely using an excellent tool called nmap.

Blog post explaining how to remotely find IP addresses using nmap.

To SSH into your Raspberry Pi from a Linux or Apple Mac computer this is very easy. You can just type your username and IP address into the command line using the following format:

ssh username@IPaddress




Ensure you substitute username with the username you are wanting to log into the remote computer with. The IP address should take the format 192.168.1.66

You may get a message explaining that the authenticity of the host cannot be established, and if you are sure you want to continue connecting.  You will only see this message the first time you SSH into your Raspberry Pi. Simply type yes.




You will then be asked for your password, enter the password for the username you are trying to connect with.

For windows this is a little more tricky to set up as it requires an additional piece of software called PuTTY. However once installed this is really simple to use.

First go to the PuTTY website, www.putty.org, download and install the software.

Once installed load PuTTY





  • Under Host Name (or IP address) type in the IP address you would like to connect to.
  • Select the SSH radio button.
  • In the box under Saved Sessions type in a name to identify this computer, such as Raspberry Pi, and then click Save.
  • Clicking on Open should now start your SSH session.

Next time you want to SSH into your Raspberry Pi you just need to load PuTTY, click on the saved session to highlight it and then click Open. Once you have typed in your password, when asked, you have remote access to your Raspberry Pi.