I am deploying raspberry pis in classrooms and I would like to store an id on each of them that is not linked to the MAC address, as the hardware might be replaced, but the classroom id shouldn't change. The only thing I can think of is to create a file in each of the pis, and write the id in it.

I was wondering if anyone had thought of a more clever way of solving this problem.


3 Answers 3


The Pi's hostname might be the best option. This way, you can even identify each Pi over the network. Another advantage to this method is that it shows the hostname (by default) at the beginning of each line in the command line.

For example:

If you had ten RPis in room A-14, then you could change the hostname on each one to:


and so on. Or, to make it smaller:


If you had different models, you could also include the model name in the hostname:


These hostnames would be visible on the network and you could ssh into any of them without their respective IP address.

There are three ways to change the hostname in Raspbian.


The command:

sudo hostname -b "NEWHOSTNAME"

will change the hostname to NEWHOSTNAME upon the next boot.


Bring up the Raspbian config with:

sudo raspi-config

Scroll down to advanced options, and then the second option is hostname. Type in what you want the new hostname to be, and it will change upon the next boot.


You can edit /etc/hosts with sudo nano /etc/hosts and change this line: raspberrypi

Just change raspberrypi to your new hostname. Don't change any of the other lines.

You don't have to do all three methods, just one will be enough!

Something important to note:

This is not hardware dependent. At all. Even if you replace the entire RPi, as long as you are using the same sd card, the hostname will not change. You can even move the sd card between models and it will keep the hostname you have set.


The Pi has a unique Serial Number. This should uniquely identify each Pi. The Ethernet MAC is related to this, and similarly unique.

Any other solution, such as creating files or hostname involves storing something on the SD Card, so at best this identifies the SD Card. This may be what you want if you want to tie user data to the ID.

Edit Based on your comment there are still many answers, depending on what you want to achieve.

  1. If you want to distinguish users - give them a unique username. This is the traditional 'NIX approach.
  2. If you want to distinguish users machines on a network give each a unique hostname.

Either or these will give a visually distinct prompt, and you can combine both.

  • yes, I want to tie user data to the id, that's why I don't want to use the MAC address, in case hardware needs to be replaced. Feb 12, 2016 at 22:57

So, after re-reading the OP's question and one of his comments, I went out and did a bit of research.

If you want user specific identification, that does not depend on hardware, and is not a file or something of the like; you can set a user specific hostname. (I know, back to hostnames...)

This question, on the U&L SE, seems to be talking about this.

Alternatively, if you don't need something that can be seen by outside computers, and just something that the user can see, you can change the command line prompt.

Simply edit ~/.bashrc. You'll have to do some research on your own about how to format this, as I have no idea. But here is a good place to start. You could change ~/.bashrc so that the command prompt shows user1@raspberrypi-user1 ~ $ or simply user1-A19 ~ $. If user1 is logged in on the Pi in room A19. You can change this however you like.

This is not changing the hostname, the only thing that can see this is the user that's logged in, looking at the screen. So it can not be seen over the network which Pi is which, they will seem identical.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.