π Raspberry Pi β Change Default Login (2025 Security Best Practice Guide)
π§² Introduction β Why Change the Default Login?
The default Raspberry Pi username pi
and password raspberry
are publicly knownβand leaving them unchanged is one of the most common security risks. Changing these credentials immediately helps protect your Pi from brute force attacks, especially when connected to a network or internet.
π― In this guide, youβll learn:
- How to change the default password securely
- How to create a new user and remove the
pi
user - How to update autologin for GUI and headless setups
- Real-world scenarios where user hardening matters
π Step 1: Change the Default Password
β Change password for current user:
passwd
If you’re logged in as pi
, this will prompt for a new password.
π€ Step 2: Create a New User with Sudo Access
β Add new user:
sudo adduser myuser
Follow the prompts to set a secure password and user info.
β
Add user to sudo
group:
sudo usermod -aG sudo myuser
π Step 3: Switch to the New User
Log out and log back in as:
myuser
Or switch session:
su - myuser
β
Ensure everything works (Wi-Fi, sudo, file access) before deleting pi
.
π§Ή Step 4: Disable or Remove the pi
User
β
Disable pi
:
sudo passwd -l pi
This locks the account but retains files and config.
β
Or delete pi
:
sudo deluser pi
sudo rm -rf /home/pi
β οΈ Only delete pi
if your new user is working correctly and has sudo access.
π₯οΈ Step 5: Update Autologin for Desktop (GUI Users Only)
If Raspberry Pi is set to autologin as pi
, youβll need to update the systemd service.
β Edit autologin config:
sudo nano /etc/lightdm/lightdm.conf
Find and update:
autologin-user=myuser
Save and reboot:
sudo reboot
β GUI will now autologin as the new user.
π Bonus: Update File Permissions
If you’ve migrated files from pi
:
β Transfer files and update ownership:
sudo cp -r /home/pi/* /home/myuser/
sudo chown -R myuser:myuser /home/myuser
π§ Why Default Login Changes Matter
π Risk | β οΈ Without Change |
---|---|
SSH brute force attacks | Username + password widely known |
Scripted IoT hijacking | Bots target pi@raspberrypi |
Public Wi-Fi vulnerabilities | Passwords guessed in seconds |
Misuse on shared networks | Anyone with access = root risk |
π Summary β Recap & Next Steps
Changing the default pi
login credentials is one of the simplest and most powerful ways to improve Raspberry Pi security. Whether you create a new user or harden pi
, your system becomes far less vulnerable to common exploits.
π Key takeaways:
- Use
passwd
to change password oradduser
to create a secure new user - Add new user to
sudo
and test it before removingpi
- Update GUI autologin and transfer files if needed
- Disable or delete
pi
only after full testing
βοΈ Real-world relevance: Critical for Pi used as servers, IoT devices, or remote nodes where unattended access is enabled.
β FAQs β Changing Raspberry Pi Default Login
β Is it safe to delete the pi
user?
β Yes, as long as your new user has full access and sudo rights. Always test thoroughly first.
β What happens if I forget the new userβs password?
β You can reset it by booting into recovery mode or using a keyboard + monitor to access single-user mode.
β Will my software or scripts break if I delete pi
?
β
Possiblyβscripts referencing /home/pi
may fail. Update paths or keep pi
disabled but not deleted.
β How do I check who has sudo access?
getent group sudo
β This lists all users in the sudo group.
β Can I rename the pi
user instead?
β
Not recommended. Better to create a new user, migrate, and then remove pi
.
Share Now :