Monday, 9 September 2013

How to set the root password on a Raspberry Pi

To do anything useful on your Raspberry Pi you'll need root access.

NB: Please read and follow the blog tutorial on how to perform basic security hardening on your Pi, otherwise setting a route password is pointless. Because, the default configuration allows root commands to be executed with or without a root password.

A lot of the commands will get you to do "sudo ...and then a command that needs root access"

E.g.
$ sudo ifconfig -a

Which means, run the command "ifconfig -a" as root - su, superuser. But eventually you'll get tired of using sudo when you want to do a load of root commands. You'll want to become su (root) and then run the commands as they are, i.e. without having to put sudo in front of each one.

But, you'll need a root password. Without one, you're leaving your machine wide open to anyone being able to do anything to it,

So, set a root password:

$ sudo passwd
(enter a password to use, and enter it again to confirm it when asked)

That's all you do.

Try it:

$ su
(put in the root password you set, when asked for the password)

# (now you have root access)

Press <ctrl-d> to exit from # (root commands) to $ (non-root commands)

Male sure your root password is not easily guessable, and don't tell it to anyone who doesn't need it. Also, make sure YOU can remember it. Once it's set, you won't be able to gain root access without it.