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
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.