Change your username and password from the command line
You can change both your username and password in Ubuntu using the terminal. The process is straightforward: you use the usermod command to rename your account and the passwd command to set a new password. Both commands work whether you are logged in as the user whose details you want to change, or as the root user making changes to another account.
The key difference is that a regular user can only change their own password without entering a password first, but changing a username always requires root access — either by using sudo or by logging in as root. If you are the only person on your machine, you likely have sudo access already. If you are unsure, try typing sudo -v in the terminal; if it asks for a password and accepts yours, you have sudo access.
Key Takeaways
- Change your password with passwd at the terminal; you do not need root access to change your own password.
- Change your username with sudo usermod -l newusername oldusername, which requires sudo access and works while you are logged in.
- After renaming your username, you should also rename your home directory from /home/oldusername to /home/newusername using sudo mv.
- If you forget your password and cannot log in, you will need to boot into recovery mode or use another account with sudo access to reset it.
- Changing your username does not affect files you own; Ubuntu tracks ownership by user ID, not by the name you see in the terminal.
Changing your password as the current user
Open the terminal and type passwd, then press Enter. Ubuntu will ask you to enter your current password first. Type it in (the cursor will not move, which is normal) and press Enter again. Then type your new password twice — once to enter it, once to confirm it matches.
If the password is too straightforward, Ubuntu will warn you but usually let you set it anyway. If you see "Authentication token manipulation error," your home directory may have a permissions problem; try restarting and running the command again, or contact your system administrator if this is a work machine.
Changing another user's password as root or sudo
If you have sudo access, you can reset another user's password without knowing their current one. Type sudo passwd username (replace username with the actual account name), then press Enter. Ubuntu will ask for your own password, not the target user's password. Once you enter it, you can set a new password for that account.
This is useful if someone has forgotten their password and you are the system administrator. The user can then log in with the temporary password you set and change it themselves using the passwd command.
Changing your username while logged in
To rename your own account, type sudo usermod -l newusername oldusername (replace both parts with your actual old and new usernames). Ubuntu will ask for your password, then make the change. You will still be logged in under the old name in your current terminal session, but the next time you log in, you will use the new username.
After you change your username, you should also rename your home directory so the path matches. Type sudo usermod -d /home/newusername -m oldusername. The -m flag tells Ubuntu to move all your files from the old directory to the new one. If you skip this step, your home directory will still be named after your old username, which can cause confusion.
Changing another user's username
If you have sudo access and want to rename someone else's account, first make sure that user is not logged in. Type sudo usermod -l newusername oldusername, then sudo usermod -d /home/newusername -m oldusername. The second command moves their home directory and updates the system to point to the new location.
If the user is logged in when you try to rename their account, the command will fail with a message saying the user is currently in use. Ask them to log out first, or use a different terminal session to make the change.
What happens to your files when you change your username
Your files remain yours even after you change your username. Ubuntu tracks file ownership by a number called the user ID (UID), not by the username itself. When you type ls -l in the terminal, you see the username next to each file, but that is just a label Ubuntu looks up from the system's user database. The actual owner is the UID underneath.
This means if you rename your account but forget to move your home directory, your files will still belong to you — but the system will show them as owned by a number instead of a name, which looks broken. That is why the second command (the one with -d and -m) matters: it updates the home directory path so everything stays organized and readable.
Recovering access if you forget your password
If you cannot log in because you forgot your password, you have two main options. The first is to restart your machine, hold Shift during startup to see the GRUB menu, select "Advanced options for Ubuntu," then choose "Recovery mode." From there, you can drop to a root shell and run passwd username to reset the password for any account.
The second option is to use another account on the same machine that has sudo access. Log in as that user, then run sudo passwd yourusername to reset your password. If you are the only user and you have forgotten the password, recovery mode is your path forward. If this is a work machine, contact your IT department or system administrator.
Frequently Asked Questions
Do I need to restart after changing my username?
No. You can continue using your current terminal session with the old username, but the next time you log in (or open a new terminal window), the new username will be active. Some applications may need to be restarted to recognize the change, but the system itself does not require a reboot.
What if I change my username but do not move my home directory?
Your files will still be yours and will still work, but the system will display them as owned by a number instead of a name when you run ls -l. This is confusing but not dangerous. You can fix it later by running sudo usermod -d /home/newusername -m oldusername to move the directory and update the path.
Can I change my username without using the terminal?
Ubuntu's graphical settings process (Settings > Users) lets you change your password and your display name, but not your actual system username. To change the username itself, you must use the terminal and the usermod command.
What if the usermod command says "user is currently used by process"?
This means the user you are trying to rename is logged in or has running processes. Ask them to log out completely, close all their applications, and try again. If it is your own account, you can rename it while logged in, but renaming someone else's account requires them to be logged out first.
Will changing my password log me out of other sessions?
No. Changing your password does not end your current login sessions. You will stay logged in on your current terminal and any other open sessions. The new password takes effect the next time you try to log in somewhere.