How to rename the default account on the Raspberry Pi

The standard Raspbian OS image for the Raspberry Pi comes with a default account called “pi” (with UID 1000, and password “raspberry”). One of the first things you should do before putting the Pi on the internet is to change the password to something more secure. However, you may also prefer a different username. This is a question which has come up on the Raspberry Pi StackExchange site. The simplest thing to do is to create a new account with the desired username, then grant it sudo privileges, and then lock the “pi” account. However, sometimes it really is desirable to actually rename the “pi” account (eg. because you want it to have the UID 1000). You can do this, but it is very easy to mess up, locking yourself out of your Pi, so here is a method that I have found to work well. But BE CAREFUL! YMMV…

It is very tricky to rename an account while you are logged in to it, so first enable the root account with

% sudo passwd root

Use a secure password, even if you intend to lock the root account again later. Then log out and log back in as root. The rest supposes a desired username of “myuname” – replace with whatever you want.

# usermod -l myuname pi
# usermod -m -d /home/myuname myuname

Then log out and log back in again as “myuname”. If you are still using the default password of “raspberry” on this account, do

% passwd

and change password to something more secure. That should be it. Test carefully! “sudo” users seem to get updated OK, but check that your renamed account works and really does have “sudo” privileges before disabling the root account.

Should you prefer to disable the root account, do

% sudo passwd -l root

Technically, this just locks the password – it doesn’t completely disable the account. But that’s probably what you want.

Published by


I am Professor of Stochastic Modelling within the School of Mathematics & Statistics at Newcastle University, UK. I am also a computational systems biologist.

8 thoughts on “How to rename the default account on the Raspberry Pi”

  1. Thanks, that was useful. A bit more explanation of what the commands exactly do would make it even better.
    From the usermod man page:

    -l, –login NEW_LOGIN
    The name of the user will be changed from LOGIN to NEW_LOGIN.
    Nothing else is changed. In particular, the user’s home directory
    or mail spool should probably be renamed manually to reflect the
    new login name.

    -d, –home HOME_DIR
    The user’s new login directory.

    If the -m option is given, the contents of the current home
    directory will be moved to the new home directory, which is created
    if it does not already exist.

  2. Also consider renaming the ‘pi’ group:

    groupmod -n myuname pi

    Also, /etc/sudoers was not updated. I had to edit the file as root and change the last line to:

    myuname ALL=(ALL) NOPASSWD: ALL

  3. This didn’t work for me, as a small number of processes were still owned by user ‘Pi’ even after I had logged out and logged back in as root. It therefore wouldn’t allow me to change ‘Pi’ to a different username.

  4. Great post. Worked just fine. I also chose to rename the groups. Also, take care that any cron jobs under that user disappear so you will need to recreate them.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s