Change your Raspberry Pi username from the command line
The fastest way to change your Raspberry Pi username is to log in as root, rename the user account, and rename the home directory. You will need terminal access and the ability to run commands with elevated permissions. This method works on any Raspberry Pi running Raspberry Pi OS, whether you are using the desktop or headless (command-line only) setup.
The process takes about five minutes and requires you to log out of your current user account, switch to root access, and run three commands in sequence. After the change takes effect, you log back in with your new username and the old one no longer exists on the system.
Key Takeaways
- You must log out of the user account you want to rename before you can change its username.
- The command usermod -l newname oldname renames the account itself, and usermod -d /home/newname -m oldname renames the home directory.
- You need root access to run these commands, which you can get by logging in as root or using sudo from another administrator account.
- After renaming, log back in with your new username and verify the change worked by running the whoami command.
Step-by-step: renaming your user account
Start by opening a terminal on your Raspberry Pi. If you are using the desktop, click the terminal icon in the taskbar or open the applications menu and select Terminal. If you are using headless mode, you are already at the command line.
Log out of your current user account by typing logout and pressing Enter. This disconnects your user session so the system will let you rename the account. You will return to the login prompt.
Log in as root by typing root at the login prompt and entering the root password. On a fresh Raspberry Pi OS installation, the default root password is often blank — press Enter if no password appears to work. If you have never set a root password, you may need to enable root login first by running sudo passwd root from another administrator account.
Once you are logged in as root, type the first command to rename the user account itself. Replace oldusername with your current username and newusername with what you want it to be:
usermod -l newusername oldusername
Press Enter and wait for the command to complete. You will not see a confirmation message — if no error appears, the rename worked.
Rename the home directory to match
After renaming the account, you must also rename the home directory so the system can find your files. Type the second command, again replacing the usernames:
usermod -d /home/newusername -m oldusername
The -m flag tells the system to move all files from the old directory to the new one. This is important — without it, your files stay in the old directory and your new account will not find them.
Press Enter and wait for the command to finish. Depending on how many files you have, this may take a few seconds. Once it completes, type logout to exit the root session.
Log in with your new username
At the login prompt, enter your new username and your password (the password does not change, only the username does). Press Enter to log in.
To confirm the change worked, open a terminal and type whoami, then press Enter. The system will print your new username. If it shows your old username, the rename did not complete — log out and repeat the commands above, checking for typos.
You can also check that your files are in the right place by typing ls to list the contents of your home directory. If you see your files, the rename was successful.
What to do if you cannot log in as root
Some Raspberry Pi OS installations disable root login for security reasons. If you cannot log in as root, you can still rename your account using sudo from another administrator account. Ask someone with admin access to log in, open a terminal, and run the commands with sudo in front of them:
sudo usermod -l newusername oldusername
sudo usermod -d /home/newusername -m oldusername
The person running these commands does not need to log out of their own account first — sudo lets them run individual commands with elevated permissions. After the commands finish, you can log in with your new username.
Fixing permissions if files are not accessible
In rare cases, files in your home directory may have the wrong ownership after a rename, and you will not be able to open or edit them. This happens when the rename command does not complete fully. You can fix this by running a command that reassigns ownership of all your files to your new username.
Log in as root or use sudo, then type:
chown -R newusername:newusername /home/newusername
This command walks through every file and folder in your home directory and assigns them to your new username. The -R flag means "recursive" — it applies the change to all subdirectories as well. After this runs, you should be able to access all your files normally.
Frequently Asked Questions
Will changing my username affect my password?
No. Your password stays the same — only the username changes. You log in with your new username and your old password.
Can I change the username while I am logged in?
No. The system will not let you rename an account that is currently in use. You must log out first, then log in as root or another admin account to run the rename commands.
What if I made a typo and renamed my account to the wrong name?
You can rename it again. Log out, log in as root, and run the usermod commands a second time with the correct name. The process is the same whether you are renaming for the first time or fixing a mistake.
Do I need to change anything else after renaming my username?
Most programs and settings will work fine with the new username. If you have scripts or configuration files that reference your old username by name, you may need to update those manually. Check any startup scripts or cron jobs you have set up.
Can I rename the default "pi" user?
Yes. The "pi" user is just a regular account on Raspberry Pi OS. You can rename it the same way you would rename any other user, as long as you log out first and use root or another admin account to run the commands.