. Advertisement .
..3..
. Advertisement .
..4..
Linux experts have long advised against using the root account on a regular basis. This practice doesn’t just prevent you from wreaking havoc on your system but also makes it more secure. However, it is still possible to log in as root on Raspberry Pi if you insist.
Why There Is No Root Password In The First Place
By default, there is no root password on Raspberry Pi OS – the official operating system of Raspberry Pi. It inherits this setting from Debian, the original Linux distro it is based on. Removing the root password is a precaution many Linux-based operating systems do for security reasons.
Raspberry Pi boards don’t come pre-installed with any operating system. But thanks to the Raspberry Pi Imager, the installation is fairly easy. Users can set up a new system on their boards with just a few clicks.
Since not much Linux knowledge is involved, Raspberry Pi OS is an easy solution for most users. They don’t need to be an experienced Linux user to make Raspberry Pi boards up and running. However, this approach has its downsides.
Most default system settings are left intact and unmodified by users. If Raspberry Pi OS included a root password, there would be a high chance no one changed it later.
Hackers would be able to scan for your Raspberry Pi and log in to it using the default root password. This superuser account has privileged access to the entire system, and they could mess up your board completely.
Removing the root password solves this issue. No password means no one could log in to it without using another account. It makes Raspberry Pi OS more secure for its users, most of which aren’t familiar with hardening a Linux system.
There are plenty of ways for a user to carry out administrative tasks without direct access to the root account. They can use sudo or get a root shell instead of using the root user.
Log In As Root On Raspberry Pi
Before you can log in to this superuser, you will need to create a password for it first. From the command line:
sudo passwd root
The shell may ask for the password of your account first. Type it in, and then enter the password you want to set for the root account. Confirm by typing it in again.
Keep in mind that you will see no asterisks that represent passwords like other systems. If there is no error, the passwd command will show this line:
passwd: password updated successfully
You can now log in to the root account with the su command:
su
Enter the password you have set for it.
Log In As Root On Raspberry Pi Over SSH
You can log in as root over SSH without connecting it to a monitor. Edit the configuration file, for example, with nano:
sudo nano /etc/ssh/sshd_config
Search for the line containing “PermitRootLogin” and change its setting to yes like this:
PermitRootLogin yes
Save the file and restart the SSH service to activate the new configuration:
sudo systemctl restart ssh
Now you can remotely log in to your Raspberry Pi as root over SSH.
Log In As Root On Raspberry Pi Without A Password
Due to security risks, you can try to use a root shell instead. It doesn’t change the state of the root account but still gives you equivalent access rights.
There are multiple ways to do this with sudo:
sudo -s
sudo -i
sudo su
All of them may ask for your own password. You will be given a root shell, which you can leave by typing:
exit
Final Words
Even though it isn’t recommended, you can log in as root on Raspberry Pi. Make sure you understand the risk when you change the password of that superuser account and use the root privileges with care.
Leave a comment