How to Safely Change Your Username on Raspberry Pi
I recently needed to rename a user on my Raspberry Pi, and I quickly realized it’s not as straightforward as it should be. If you’re thinking of doing the same, I’ll show you the safest approach to handle it. It’s simpler than it looks, but there are a few traps you’ll want to avoid.
A safe way to change the username is to create a new user to replace the old user. Another method is to rename the user directly with the usermod command. Both methods still require transferring home folders, services, and other settings manually.
I’ll start by explaining why you can’t just edit your username, and then show you how to safely migrate to a new user on a Linux system like Raspberry Pi OS.
If you’re new to Raspberry Pi or Linux, I’ve got something that can help you right away!
Download my free Linux commands cheat sheet – it’s a quick reference guide with all the essential commands you’ll need to get things done on your Raspberry Pi. Click here to get it for free!
Why Changing Usernames Is a Big Deal
Let’s say you’ve already got a system running on your Raspberry Pi and realize one day that you don’t like your username. Maybe you chose something silly like ‘xxfishloverxx’ to test things out, or maybe you created too common a username, like ‘pi’ or ‘admin,’ which is a security risk.
Surely, changing your username is simple—just edit the /etc/passwd file, right?

WRONG. Editing the username manually will eventually lead to a broken system.
You might also like: I tried to replace my main PC with a Pi 5, here's what happened.
That’s because your username is tied to permissions, home folders, and other configurations on the Linux file system. In other words, manually editing the username disrupts linkages that will cause the system to malfunction.
You’d think that there’d be a graphical tool to make changing your username easy, but there isn’t. You can’t do it from the Raspberry Pi OS Control Centre nor from Ubuntu’s Users menu.

The best way to change a username is to use terminal commands.
In this guide, we’ll be creating a new user and migrating everything over.
You can get answers from real experts in minutes.
Get help with your setup
You might be wondering why I’m not going to show you how to rename the username directly. That’s the traditional way, but on Raspberry Pi, it’s safer to create a new user. That way, you can’t accidentally get locked out or cause an unbootable state.
(If you still insist on doing it the traditional way, we’ll touch on it at the end.)
How to Change Your Username on Raspberry Pi OS
Here are the big picture steps to change your username:
- Create a new user with administrator privileges.
- Copy the home folder from the old user to the new user.
- Transfer file ownership and fix custom paths.
- Delete the old user.
Let’s cover each step in detail.
Note: I tested these steps on Raspberry Pi OS, but it should also work the same way on most Linux distributions.
Make a Backup
I highly recommend making a backup before attempting a username change.
If you have a lot of stuff installed, a full clone of your SD card is probably a good idea.

Create a New User
First, let’s create a new user with the username you want:
(I’ll be using ‘pat’ as the old username and ‘tom’ as the new username for our examples.)
- Open a terminal and type this command: adduser <new_username>
sudo adduser tom - You’ll be asked to set a password for the new user.
- You can skip the other questions regarding contact info if you’d like.

Next, let’s get the new user to inherit the same groups as your old user:
- List what groups the old user belongs to: groups <username>
groups pat
- Copy the output, but leave out the first group, the one that’s the same as the username. That’s because we want your new user to have his own primary group.
- Have the new user join these same groups: usermod -aG <group1,group2> <user>
(Don’t forget to add the commas.)sudo usermod -aG adm,dialout,cdrom,sudo,audio,video,plugdev,games,render,netdev tom - Verify that your new user has joined these groups.

(If you’re interested in learning more, read our article on creating a new user on Raspberry Pi.)
Congrats, your new username is active!
But it doesn’t have full access like the old user did, so let’s work on that next.
Tip: Command lines can be a pain to memorize. I put the essential Linux commands on a printable cheat sheet so you don't have to keep googling them. You can grab the PDF here if you want to save some time.
Grant Admin Privileges
Your primary user on Raspberry Pi most likely had admin privileges, AKA, a “super user” that can run restricted system commands. We want your new username to have these same powers.
Here’s how to give your new user admin privileges:
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
- Open the “sudoers” file using this special command:
sudo visudo - Scroll to the bottom of the file to find root ALL=(ALL:ALL) ALL.
- Add a similar line underneath with your new username:
myuser ALL=(ALL:ALL) ALL
- Save & exit (CTRL+X).
As an admin, your new user should now be able to use the sudo command.
Copy the Home Folder Over
Your old user’s personal files were stored in his home folder (e.g., /home/pat), the kind of stuff you use on a day-to-day basis, like app configurations, images, or SSH keys. You’ll want to give these files to your new user.
Here’s how to migrate home folders:
- Copy the old home folder to the new user: cp -a /home/olduser/. /home/newuser
The -a flag means copy in “archive mode,” which preserves permissions, symlinks, and other metadata. Don’t forget the period in the syntax.sudo cp -a /home/pat/. /home/tom - When it’s done, the files will appear in the new user’s home, but you’ll notice that they still belong to the old user and old user’s group. So we need to transfer ownership.

- Transfer file ownership to the new user: chown -R newuser:newuser /home/newuser
sudo chown -R tom:tom /home/tom

(To learn more, check out our guide: 7 Linux Commands to Easily Manage File Permissions.)
You now have all of your user files and settings, and you even kept the original timestamps of when they were created.
Log In as Your New User
Now log out, and try to log in with your new username.

– On the Desktop, go to Pi menu > Shutdown > Logout, and try to return as your new user.
– If using SSH, you should be able to log in as your new user immediately.
Either way, confirm that you’re able to log in as your new user without issue.
Play around to make sure everything still works. You can even do this test run as your new user for a few days if you want. Do your desktop applications still work the way you want? Are you hosting any services, and are they still accessible?
Once you confirm that you have a functioning system, go back to your old user and disable auto-login.
– On the Desktop, you can do this via the Control Centre.
– On the command line, you can do this with raspi-config.


Delete the Old User
This is the final step.
But wait! Don’t do this right away because there’s no going back.
You can keep the old user around as you verify everything works, until you feel comfortable and safe. I recommend going through all the Common Issues in the next section first before taking this action. After you’re done, you can proceed to delete the old user.
Delete the old user with this command: userdel -r <old_username>sudo userdel -r pat
You should run this command when logged in as your new user. It will also delete the old user’s home folder. (You did copy those files over or back them up first, right?)
Something not working? Don't waste hours going in circles. Ask in the RaspberryTips Community and get help from people who've already figured it out. Get unstuck now.
Common Issues When Changing Usernames
If you’re lucky, copying the home folder over was all you needed to do to switch to a new username. If you have a more complex system running, however, there can be a lot of edge cases to deal with.
In this section, I’ll try to cover common problems that arise when changing usernames, and what you can do to solve each one.
Will my SSH keys still work?
Yes, your old SSH keys, if you have any, should’ve been stored in your /home/olduser/.ssh folder. If you copied the old home folder to the new user and transferred ownership like we did earlier, then your SSH keys should still work without further modification.
Will my cron jobs transfer over automatically?
No, your scheduled tasks need to be dealt with manually.
Some cron jobs are run by ‘root’ while others are run by the user. The ones run by ‘root’ are fine, nothing to do there. The ones owned by your old user, however, need to be moved over.
Check which scheduled tasks are owned by your old user: crontab -u <user> -lsudo crontab -u pat -l
If you see something there, copy/paste it over to your new user’s crontab.
Will this affect mounting USB drives?
It depends on how you mounted your particular removable media in the past.
No: If you plugged the device in on the Desktop and let the system handle it for you, then it should work by simply replugging the USB device in as your new user and letting the system do it.
Yes: If you mounted your drive via the command line in the past, then it may be bugged. That’s because some operating systems mount to the /media/username folder. An easy solution is to rename the old folder to your new username, like this: sudo mv /media/pat /media/tom
More details about USB device management on Raspberry Pi here.
How do I check on services?
This is a pretty big one for me because I host a bunch of different services on my Raspberry Pi server, like Pi-Hole, Home Assistant, and Immich. You’ll want to check if your services are still working when you switch to your new user.
Some services run as ‘root,’ while others run as your user. Services that run as ‘root’ are still fine and can be left alone. The services that were installed to run as your user will need to be transferred to your new user.
Check this: 7 Surprising Uses for a Raspberry Pi
Check if your old user made any custom service files:
(Change ‘pat’ in the command below to your old username.)sudo grep -r pat /etc/systemd/system
Check if your old user currently owns any running services:
(Change ‘pat’ in the command below to your old username.)sudo systemctl --user --machine=pat@ list-units --type=service
The ones I have above are just default services for Raspberry Pi OS, which means they’ll be gone when the old user gets deleted, so there’s no need to mess with them. There wasn’t any service I had to save from this list, but if you see something custom here, you might need to reinstall it.
Bonus tip: If the terminal still feels confusing, I made a simple cheat sheet with 74 commands explained in plain English. You can grab it here for free..
In my case, I had many self-hosted services that ran as Docker containers under my old username. The easiest way to transfer ownership of those is to:
- Stop the containers.
- Log in as the new user.
- Bring the containers up as the new user.
What about startup programs, custom scripts, or config files?
In your startup files, custom scripts, or config files, you might have references to your old user folder, like PATH=/home/pat. These hard-coded references need to be updated manually.
Here are some good places to check:
| Type | Location |
|---|---|
| Desktop Autostart Entries | /home/newuser/.config/autostart/ |
| System-wide Autostart Entries | /etc/xdg/autostart/ |
| Aliases | /home/newuser/.bashrc |
| App Configuration Files | /home/newuser/.config |
In my case, I didn’t have any startup programs, and the system-wide entries were all owned by root, so no need to transfer ownership. I did have Linux aliases, but none of the commands called my old user’s path, so there was nothing for me to fix here either.
Read next: 15 Easy Projects for Raspberry Pi Beginners
Most of my problems came from the config folder (/home/tom/.config/), which had a few files with those old paths in them.
How did I discover this? By using one of my favorite ways to use the grep command:sudo grep -r "/home/pat" /home/tom
This syntax will mass search for text inside of files. It looks for ‘/home/pat’ written inside of any files in my new user’s home folder (/home/tom). You can adapt this command to search for text that might need to be updated in other places.
The first issue I found was this line in the configuration for the RPIOS file manager: ![]()
This gave me an error message when logging in. So I just edited that file and changed the reference to /home/tom/Desktop instead.
The second issue I found was a bunch of references for Chromium. Since I didn’t have any special browser settings, I just deleted its config folder (/home/tom/.config/chromium). Once I launched Chromium as my new user, the program generated a new config for me.
My third issue was custom software that I’d installed for my Pironman 5-MAX case. Since there were lots of references to binary files, the safest answer was to reinstall it from scratch.
You might also like: 7 Hidden Raspberry Pi Features You Should Be Using
Lastly, I found a bunch of matches for log files. But those were simply old records, so I didn’t feel a need to do anything with them.
Hopefully I gave you a good idea of how to handle different situations.
What about other files located outside of home?
When you change your username, regardless of which method you used, it won’t catch every file on the system that belongs to the old user.
You can search for all files belonging to the old user with this command find / -uid <user_id>
The UID can be found in /etc/passwd (or in /etc/passwd- if the user was deleted.)
It’s the first number closest to the username.
The user ‘pat’ in the example below has a UID of 1000:
After that, you can use this command to hunt for orphaned files:sudo find / -uid 1000
In most cases, you probably won’t find anything that needs migrating. If you have a simple installation, you can probably skip this part.
Truthfully, all of your search results might be temporary files in /proc or /sys that can be safely ignored. To clean up the output, I like to add these parameters to exclude certain folders: sudo find / -uid 1000 -not -path '*/proc*' -not -path '*/sys*'
You might also like: I tried to replace my main PC with a Pi 5, here's what happened.
If you find any custom files, that you specifically put there and forgot about, then you can use chown to change the ownership to your new username. (You can learn more “expert” commands in this article.)
Can I rename my existing user instead?
Yes, the textbook way to rename your existing user is with the usermod command. But the steps are more involved, and you’ll need to be more cautious to not break your system.
Here are the steps to change your username by renaming it:
- Disable auto-login for your primary user.
- Enable root login.
- Log out of your primary user and log in as root.
- Rename the old username to your desired new name:
usermod -l <new_user> <old_user> - Rename the new user’s primary group:
sudo groupmod -n <new_user> <old_user> - Transfer the home folder to the new user:
sudo usermod -d /home/<new_user> -m <new_user> - Change file ownership to the new user:
sudo chown -R <new_user>: /home/<new_user> - Log in as the new username and run some tests.
- Go through the common issues listed earlier to fix edge cases.
- Disable root login again.
After going through this process, you should have a system that works with your new username, and the days of having to log in as ‘xxfishloverxx’ will become a fond memory.
Not getting the same result?
Even when you follow every step, small differences in OS version, hardware or config can change the outcome. Instead of wasting time guessing, get help from people who have already fixed the same kind of issue.
- Get help on your exact issue
- Access step-by-step videos for tricky setups
- Browse the website without ads

nice one – thx
but I lost the purpose of changing the username
if for security then on the 1st place: disable root login and forbid ssh as root and 2nd: disable ssh password login – just use the key for login
Yes, you are right.
The goal in this article was just to explain how to do it, not why 🙂
The sed variant is a bad idea as there are /etc/group entries named “spi” and “gpio”, both which would be mangled with the new user name: s<new_user>
What’s also missing is /etc/sudoers.d/010_pi-nopasswd which enables passwordless sudo for the “pi” user. There’s probably more.
Good comment about the sed command, didn’t think of that :/
And yes, for sudo, I could add it in the linked article.
Thanks!