The fastest way to rename your Pi account
The quickest method is to create a new user account with the name you want, then delete the old one. This avoids the complications that come with renaming a user while their files and processes are still active. You will need to log in as root or use sudo (a command that lets you run administrator tasks) to make these changes.
If you are running the standard Raspberry Pi OS, you already have the tools you need. The process takes about five minutes and does not require installing anything new.
Key Takeaways
- Creating a new account and removing the old one is safer than renaming the existing user directly, because it avoids permission conflicts on your files.
- You will need to log in as root or use sudo commands, which means you need to know your current password or have physical access to the Pi.
- Any files owned by the old account will still exist on your system after deletion, so back up anything you need before you start.
- If you use your Pi for home automation, file sharing, or remote access, you may need to update those services to use the new username.
Create a new account with your preferred username
Open a terminal window on your Pi (or connect via SSH if you are accessing it remotely). Type the following command, replacing newusername with the name you want:
sudo useradd -m -s /bin/bash newusername
The -m flag creates a home directory for the new user. The -s /bin/bash flag sets bash as the default shell, which is what most Raspberry Pi users expect. After you run this command, set a password for the new account by typing:
sudo passwd newusername
The system will prompt you to enter and confirm a password. Choose something you can remember.
Add the new user to the sudo group
If your old account had permission to run commands with sudo, your new account needs the same permission. Type:
sudo usermod -aG sudo newusername
This adds your new user to the sudo group, which grants administrator privileges. Without this step, you will not be able to install software or make system changes from the new account.
Log in with the new account and verify it works
Log out of your current session and log back in using your new username and password. Open a terminal and run a command that requires sudo, such as sudo apt update, to confirm that your permissions are set up correctly.
If you are accessing the Pi remotely via SSH, test the connection with your new credentials before you delete the old account. This way you know you can still reach the system if something goes wrong.
Delete the old account
Once you have confirmed the new account works, remove the old one. Log in as the new user (not the old one), then type:
sudo userdel oldusername
Replace oldusername with the name of your original account. This removes the user from the system but leaves their home directory and files intact. If you want to delete the home directory as well, use:
sudo userdel -r oldusername
The -r flag removes the home directory and all files inside it. Only use this if you have already backed up anything you need to keep.
Update services that reference the old username
If you use your Pi for specific tasks — such as running a web server, file sharing, or home automation software — those services may have configuration files that reference your old username. Search for the old username in your system configuration by typing:
sudo grep -r oldusername /etc
This searches the main configuration directory for any mention of your old username. If you find matches, you will need to edit those files and replace the old username with the new one. The exact files depend on what software you are running.
Common places to check include /etc/cron.d (for scheduled tasks), /etc/sudoers.d (for permission rules), and configuration directories for any services you have installed.
What to do if you cannot log in as root
Some Raspberry Pi setups do not allow direct root login. If you get a "permission denied" error when trying to use sudo, you may need to enable the root account first. Type:
sudo passwd root
This sets a password for the root user. After that, you can log in as root in a new terminal session and run the commands above without the sudo prefix. When you are finished, you can disable the root account again by typing sudo passwd -l root.
Frequently Asked Questions
Can I rename my account without creating a new one?
Yes, you can use the usermod command to rename a user directly, but it is riskier. You must not be logged in as that user when you rename it, and you need to manually update the ownership of all their files. The create-and-delete method avoids these complications.
What happens to my files when I delete the old account?
By default, the files stay on your system but become owned by a user ID that no longer exists. If you use the -r flag, the home directory and everything in it are deleted. Always back up important files before you delete an account.
Do I need to restart my Pi after changing the username?
No restart is required. The changes take effect when ready. If you are running services that use the old username, you may need to restart those services individually after you update their configuration files.
Can I change the username of the default pi user?
Yes, the process is the same. The "pi" user is just a regular account on Raspberry Pi OS. Create a new account, move any files you need, and delete the old one. Many home automation and Pi-specific tools expect the pi user to exist, so check your software documentation before you remove it.
What if I forget the password for my new account?
If you have physical access to the Pi, you can boot into recovery mode or use a live USB to reset it. If you are accessing it remotely, you will need to contact someone with physical access or use your old account (if it still exists) to reset the new one with sudo passwd newusername.