If you're in the console of the pi there is a way to get around this without having to make another user (or set a pw on root):

Assuming nothing else is running with your username other then the shell on the console - no X session, no ssh login, etc:

exec sudo -s
cd /
usermod -l newname -d /home/newname -m oldname

The reason this works:

sudo -s tells sudo that instead of just running the command as another user, it should run a new shell as the given user

exec tells the shell that instead of spawning off a new process when it runs a command (hence leaving the shell process running as the logged in user), that the shell should overwrite itself with the new process. This means that when the exec command ends the shell is gone. In the case of a login shell, that equates to disconnecting from the login.

the cd / is optional. At a minimum, things get a bit confusing if you move a directory you're in (your login starts out sitting in the user pi home directory). Sometimes this will cause a fail, so it's better to be safe than sorry.

Therefore with exec sudo -s you're overwriting your shell with a new shell that has been created as a different user (the root user in this case).

P.S. be sure to give usermod -d a full (hard link) path or you'll end up moving the account's home to somewhere you don't expect and have a bogus directory entry in passwd.

The answers above are correct, I just want to give another option that may suits you better.

Assuming:

A brand new raspberry pi

You want to change the default username pi to mypie

You want to adapt also the main group from pi to mypie

You want other things to work out like sudo and auto-login

Proceed to:

Step 1: stop user pi from running before the change.

Boot it, go to RPI configurations and

allow SSH,

disallow auto-login

hit ok

Press ALT+F1 to go to the first tty

Escalate to root with sudo su -

Edit $vim /etc/systemd/system/autologin@.service

Find and comment (#) the line

#ExecStart=-/sbin/agetty --autologin pi --noclear %I $TERM

you can uncomment it later if you want console autologin, but then don't forget to change the user pi to your new username mypi

Create a new root password with passwd. (DON'T FORGET IT)

Type reboot

Step 2: make the user change

If you see the graphical login prompt, you are good. Do not login. Instead, press ALT+F1 (* if you want to do it via ssh, see the apendix)

After ALT+F1, you should see a login question (and not an autologin).

Login as root with your root password. Now you are alone in the system, and changes to pi will not be met with usermod: user pi is currently used by process 2104. Check with ps -u pi to see an empty list.

Very carefully, key by key, type usermod -l mypie pi . This will change your username, from /etc/passwd file, but things are not ready yet. Anyway, check with tail /etc/passwd and see the last line mypie:1000:... The 1000 is the UID and it is now yours.

Try su mypie just to be sure. Do nothing. Just exit again to root. It should work. Now you need to adjust the group and a $HOME folder.

Step 3: make the group change

Type, again carefully, groupmod -n mypie pi . This will change the pi group name. Check it with tail /etc/group and you will see the last line the new name associated with GID 1000.

Just to clarify, type ls -la /home/pi and you will see that the pi HOME now belongs to you, mypie.

Step 4: lets adopt the new home.

I see in the answers above the creation of a new folder, copying everything. No need. Lets just use the same.

First move to cd /home to make it easier. Type ls -la and see pi, onwer mypie group mypie

Type carefully: mv pi mypie . You now need to associate this change with your new user.

Type carefully: usermod -d /home/mypie mypie . This will change your home directory. Check it with tail /etc/passwd and look at the sixth field (separated by :).

Step 5: some adjusts after the fact.

Reboot with reboot

Login as your new user mypie in the graphical interface.

Open a terminal.

Change your password

Type passwd to change the password of mypie to something else than raspberry

Type sudo su - and you will be asked your password.

auto-login again if you will (I don't recommend, but well)

If you want to autologin your new account, edit the file:

$vim etc/lightdm/lightdm.conf

find the line with #autologin-user=, change it to autologin-user=mypie (no comment #)

If you want back the ALT+F1 autologin, find and edit the file:

$vim /etc/systemd/system/autologin@.service and change the line

#ExecStart=-/sbin/agetty --autologin mypie --noclear %I $TERM

Make your sudo passwordless again (I don't recommend as well)

Move yourself (root) to cd /etc/sudoers.d

Rename the file 010_pi-nopasswd to 010_mypie_nopasswd

Open it vim 010_mypie_nopasswd and change the line pi ALL=(ALL) NOPASSWD: ALL to, obviously mypie ALL=(ALL) NOPASSWD: ALL. It is read-only, so save it forcing with :x!

Step 6: reboot

Appendix - ssh

You may want to do this via ssh. For this to work, first you need to allow root login.

Find the file /etc/ssh/sshd_config

Comment the line #PermitRootLogin without-password

Add the line PermitRootLogin yes

Save, exit, restart ssh with /etc/init.d/ssh restart

After you have done it, undo this changes as they are too dangerous to let that way.

Same file, delete PermitRootLogin yes line and remove the comment from PermitRootLogin without-password

Note 1: This is a guide, and the content deals with very dangerous commands. Backup first, or be aware that maybe you will need to burn again your image. As I am assuming a brand new raspberry pi, there is not much to backup anyway. But if you adapt it to another situation, be advised.

Note 2: There might be more things to change. As I am new to the Raspberry pi (I got mine 2 days ago), I may find other adjusts I left out and I will edit this answer again.

Note 3: My first attempt was to move pi user and pi group to another UID and GID (1001) and create a new user for me as 1000. That didn't quite go as I planned and I needed to burn my SD card again after spending the whole day trying to figure out why the "configure you pi" program would not work anymore. But well, this way here is far easier anyway, so here you go: a new pi with just your username as UID 1000 (and all the good stuff in your home).

I don't have enough points to just put this as a comment, but if booting into safe mode doesn't work, you can try doing this by creating a temporary account and operating from there. See the description here: https://askubuntu.com/a/34075/112715