For those people who (like me) have more than one Pi, and even for those who have more than one SD card, the ability to change the hostname is invaluable. Here’s how you do it.
You need to change two files.
Firstly, edit (using nano, or other editor) the file
/etc/hostname
Change whatever is currently in there to the name you want. For this example, we’ll set our Pi to have the name ‘banana’. So, ‘banana’ (without the quotes) is the only thing that should be in that file. Save it.
Secondly, edit the file
/etc/hosts
Change the ‘127.0.0.1’ line to (for our example):
127.0.0.1 banana
That’s it! Reboot and you should get a login prompt with your new hostname.