This article provides a practical and technical explanation of the topic, including real-world use cases and insights.
How to Change a Raspberry Pi Linux Username and Password
A professional step-by-step guide to safely rename a Raspberry Pi/Linux user from maurise to mourad, change the home directory, and set a new password without losing SSH access.
“` “`Introduction
In Linux, changing a username is possible, but it must be done carefully. If you rename the same user that is currently logged in, you may face session, permission, or SSH problems.
“`In this tutorial, we will safely change the old username maurise to the new username mourad. We will also change the home directory and set a new password.
What We Will Do
- Create a temporary administrator account.
- Log in using the temporary account.
- Rename the Linux user from maurise to mourad.
- Rename and move the home directory.
- Rename the user group.
- Set a new password.
- Test SSH login with the new username.
- Remove the temporary administrator account.
Step 1: Connect to the Raspberry Pi
“`First, connect to your Raspberry Pi using the current username. In this example, the Raspberry Pi IP address is 192.168.1.104.
ssh maurise@192.168.1.104
After entering this command, type the current password of the user maurise.
“`Step 2: Create a Temporary Admin User
“`We need a temporary administrator user because Linux cannot safely rename the currently active user session.
sudo adduser tempadmin
You will be asked to enter a password for tempadmin. Choose a temporary password that you can remember.
Now give the temporary user administrator permissions by adding it to the sudo group.
sudo usermod -aG sudo tempadmin
After that, log out from the current SSH session.
exit
“`
Step 3: Log In with the Temporary Admin User
“`Now connect again to the Raspberry Pi, but this time use the temporary administrator account.
ssh tempadmin@192.168.1.104
Enter the password that you created for tempadmin.
“`Step 4: Rename the User from maurise to mourad
“`Now rename the old Linux username maurise to the new username mourad.
sudo usermod -l mourad maurise
Step 5: Rename and Move the Home Directory
“`After renaming the username, you should also rename the home directory from /home/maurise to /home/mourad.
sudo usermod -d /home/mourad -m mourad
Step 6: Rename the User Group
“`On many Raspberry Pi/Linux systems, the user has a group with the same name. If the old group is named maurise, rename it to mourad.
sudo groupmod -n mourad maurise
Then fix the ownership of the new home directory.
sudo chown -R mourad:mourad /home/mourad
“`
Step 7: Set a New Password for mourad
“`Now set a new password for the renamed user mourad.
sudo passwd mourad
Step 8: Make Sure mourad Has Sudo Access
“`To make sure the new user can run administrator commands, add mourad to the sudo group.
sudo usermod -aG sudo mourad
Check the user information and group membership.
id mourad
If everything is correct, you should see sudo in the list of groups.
“`Step 9: Test SSH Login with the New Username
“`Before deleting the temporary administrator account, open a new terminal window on your computer and test SSH login with the new username.
ssh mourad@192.168.1.104
Enter the new password. If the login works, the username and password were changed successfully.
Step 10: Remove the Temporary Admin User
“`After confirming that the new user works correctly, you can remove the temporary administrator account.
sudo deluser tempadmin
Then remove its home directory.
sudo rm -rf /home/tempadmin
Final Result
“`Your Raspberry Pi/Linux system now uses the new username and password.
| Old Username | maurise |
|---|---|
| New Username | mourad |
| New Home Directory | /home/mourad |
| SSH Login | ssh [email protected] |
Useful Verification Commands
“`You can use these commands to verify that the change was applied correctly.
whoami
pwd
sudo whoami
If the last command returns root, then sudo access is working correctly.
“`Conclusion
This article highlights key aspects and practical applications of the discussed technology.
References
- IEEE Xplore Digital Library
- SpringerLink Research
- Google Scholar
Author: Mourad Elgorma
IoT & Networking Specialist
👉 Read more: Explore more ICT articles

