HOWTO · Raspberry Pi

How to Login as Root User on Raspberry Pi

Learn how to use root access on Raspberry Pi OS, set an optional root password, and make a safer SSH choice.

On this page

To administer Raspberry Pi OS, use sudo from an account that is allowed to use it. For a temporary interactive root shell, run sudo -i; you do not need to enable a root password. Account names, initial credentials, and sudo permissions depend on the OS release and how the device was set up, so do not assume every installation has a pi account or a shared default password.

Understand root access on Raspberry Pi OS

The root account has permission to change system-wide files and settings. A root shell makes every command in that shell run with those privileges, so use it only for tasks that need them and leave it when finished. For one administrative command, prefix it with sudo; for a sequence of commands, an interactive shell may be more convenient.

On some installations, the setup process creates an administrator account and grants it sudo access. The account may be named pi, or it may have another name. Check which account you are using with id -un:

id -un
root

The command prints the current account name. In the execution environment used for this example, its observed output was root; on your Pi, it prints the account you are currently using. If sudo reports that the account is not permitted to use it, sign in with an administrator account or use the recovery process for that specific installation; changing to root does not grant permission to an account that lacks it.

Open a root shell from the pi account

If you are signed in as pi and that account has sudo permission, open a root login shell with:

sudo -i

Enter the password for your current account if prompted. The shell prompt may change, but prompt formatting varies; use id -un to confirm the active account. Commands you run in this shell have root privileges. Type exit or press Ctrl+D to return to the original account. You can also run a single administrative command with sudo command, replacing command with the command you need.

Set a password for the root account

A separate root password is optional and is not needed for sudo-based administration. If you have a specific reason to enable password-based root access, and your current account has sudo permission, set it interactively with:

sudo passwd root

Follow the prompts to enter and confirm the new password. This changes the root account’s password; it does not change your current account’s password. Afterward, su - can open a root login shell by prompting for that root password. Use exit or Ctrl+D to leave it. Keep the password private and prefer sudo when it meets the task, so administrators can use their own accounts and actions remain attributable to them.

Configure SSH access for root

Direct root login over SSH gives remote connections broad control of the device. The safer choice for routine administration is to connect as your normal account and run needed commands with sudo. This also avoids enabling password-based root login.

If remote root login is an explicit requirement, inspect the effective SSH server configuration and authentication policy for your installation before changing anything. PermitRootLogin prohibit-password disables password and keyboard-interactive authentication for root. Other authentication methods may still be available, depending on the effective SSH configuration. See the official OpenSSH sshd_config documentation for PermitRootLogin. Do not replace the directive with yes as a general fix. A key-only setup still requires a protected private key and the correct public key for root, and SSH configuration can include additional files or rules that affect the result. Keep an existing administrative session open while applying a planned configuration change, then verify a separate connection before closing it. Service names and restart procedures can vary by installation.