- General Access Control Concepts in Raspberry Pi OS and Root Account
Log in as Root From the Default
- Setup a Password for Root User in Raspberry Pi OS
- Access Root User via SSH Session
This article will introduce several cases of logging in as the root user on Raspberry Pi OS.
General Access Control Concepts in Raspberry Pi OS and Root Account
As you already might know, Raspberry Pi OS is based on Debian Linux, and many core parts of the operating system have the same interface as far as the system administrator is concerned.
Generally, a Linux-based system can have multiple users, and they can simultaneously use the resources on it without conflicting with each other. Linux systems also define a special administrative user called -
root, which is capable of manipulating every aspect of the system. Although, this unlimited permission raises the issue of properly guarding access to it, which is why some Linux distributions like Raspberry Pi OS disable it by default.
Newly installed Pi OS has the default
pi user and the password
raspberry. These credentials are used for logging in on the first boot. Also, at this stage, the system setup GUI prompt will suggest changing the default password. If you missed this step on the initial setup process, you could always modify it using the
passwd command via a CLI.
Log in as Root From the Default
In this case, we are assuming that you are logged in as the
pi user and have access to the command-line interface. Enter the following command to log in as the
The above method should work without requiring any password on the current Pi OS version, assuming that corresponding system config modifications weren’t done until this point. Note that the
sudo command is used to elevate the privileges for regular users of the operating system to the superuser level. This way, a single command (like
su) is executed with the root privilege, and once it returns, the control is given back to the regular user. This technique is used as a security measure for large multi-user systems, and it has many benefits.
Here, we essentially utilize
sudo provided privileges to run
su command, which yields a
root shell access. Notice that executing a
sudo prefixed commands is in itself a privilege for regular users, and the
pi user happens to have that by default in Pi OS. Once you have accessed a
root shell, you are able to run all commands using the superuser privileges, and when you are done, you can exit it using the Ctrl+D shortcut.
Setup a Password for Root User in Raspberry Pi OS
The previous solution to access the
root user is a small hack that requires you to log in as
pi user first, but we can have a solution where a
root user is activated and has a separate password setup. This requires
sudo privileges to configure at first. Thus, we need to run the following command from the
sudo passwd root
This command will prompt for a new password to be entered and then retyped once again. Consequently, you can log in as
root user from the current terminal session, or you may log out and log in using new
root credentials. Note that you’d need to run
su command without
sudo prefix to access the root shell using a new password.
Access Root User via SSH Session
If you followed the last instruction and did set up a separate password for the
root user, you can proceed with the next commands and allow access over SSH. At first, you need to identify if your user is
root, which you can quickly notice on the left of the CLI line or retrieve it by executing a
whoami command. Then you can run one of the commands based on the current logged in user:
sudo nano /etc/ssh/sshd_config
These commands open the SSH configuration file using a CLI text editor
nano, a more user-friendly interface for Linux/Unix beginners. However, you can open this file for editing with any CLI text editors you’re familiar with e.g., Vim or Emacs. Then you should look for a line that says:
# to uncomment the text and replace
yes string. Then, save the changes by clicking Ctrl+X and then inputting
Y. At this point,
nano will prompt to overwrite the given file, and you can confirm by pressing the Enter key. Finally, you need to reboot the SSH service using the next command for it to load a new configuration:
sudo systemctl restart ssh
systemctl restart ssh
- MySQL in Raspberry Pi
- Setup a Raspberry Pi File Server
- DNS Server on Raspberry Pi
- Dropbox on Raspberry Pi
- Plex Media Player on Raspberry Pi
- Chromium OS on Raspberry Pi