Securing your Raspberry Pi starts with strong passwords and proper user management. The default “pi” user and password pose a significant security risk. This guide will walk you through the essential steps to harden your Raspberry Pi’s security.
Table of Contents
- Setting a Password During Setup
- Changing the “pi” User Password
- Changing Passwords for Other Users
- Managing the Root Password
- Creating New Users
- Granting sudo Privileges
Setting a Password During Setup
The ideal time to set a password is during the initial setup using Raspberry Pi Imager. You’ll be prompted to create a password for the “pi” user. Choose a strong password (a mix of uppercase and lowercase letters, numbers, and symbols) and keep it safe. This proactive step eliminates the need to change the password later.
Changing the “pi” User Password
If you’ve already set up your Raspberry Pi, changing the default “raspberry” password is paramount. Use the following steps:
- Connect to your Raspberry Pi: Use SSH or a monitor and keyboard.
- Open a terminal: An SSH session already provides a terminal; otherwise, open one.
- Change the password: Execute this command and press Enter:
sudo passwd pi
- Enter the current password: Enter the current password (“raspberry” by default).
- Enter the new password: Type your chosen password.
- Re-enter the new password: Confirm your new password.
The system confirms the password change. Remember your new password!
Changing Passwords for Other Users
To modify a user’s password (other than “pi”), replace “pi” with the username in the passwd
command:
sudo passwd <username>
Substitute <username>
with the actual username. The process mirrors changing the “pi” user’s password.
Managing the Root Password
The root user possesses complete system control. Changing the root password is crucial for security. Avoid using sudo passwd root
directly. Instead, use sudo su
to become root, then change the password using passwd
:
- Switch to root:
sudo su
- Change the password:
passwd
- Enter the current password: Enter your current user’s password (not the root password).
- Enter the new root password: Enter your desired root password.
- Re-enter the new root password: Confirm the password.
- Exit root: Type
exit
to return to your normal user account.
Creating New Users
Creating separate user accounts enhances security. Use useradd
and passwd
:
- Add the user:
sudo useradd <newusername>
Replace
<newusername>
with the new username. - Set the password:
sudo passwd <newusername>
- Create a home directory (optional):
sudo mkdir /home/<newusername> sudo chown <newusername>:<newusername> /home/<newusername>
Granting sudo Privileges
To grant administrative rights, add users to the sudo
group:
- Add to the
sudo
group:sudo usermod -aG sudo <newusername>
Replace
<newusername>
with the username. - Log out and back in: The user must log out and back in for changes to apply.
By following these instructions, you strengthen your Raspberry Pi’s security. Remember to use strong, unique passwords for all users.