Change your username and password from the command line
You can change both your username and password on Ubuntu using the terminal. The process is straightforward: you use the passwd command to change your password, and usermod to change your username. Both commands run from the command line, and you need to know your current password to start.
Changing your password is the faster task — it takes one command and happens when ready. Changing your username is more involved because Ubuntu needs to update file ownership across your home directory, and you may need to log out and back in for the change to take full effect.
Key Takeaways
- To change your password, open the terminal and type passwd, then enter your current password and your new password twice.
- To change your username, use sudo usermod -l newusername oldusername, but you must run this command while logged in as root or with sudo access.
- After changing your username, you should also rename your home directory from /home/oldusername to /home/newusername using sudo mv.
- Log out completely and log back in after changing your username so Ubuntu recognizes the change across all your open sessions.
- If you lock yourself out, you can reset your password by booting into recovery mode from the GRUB menu.
How to change your password in three steps
Open the terminal by pressing Ctrl+Alt+T, or by clicking the Activities menu and searching for "Terminal". Type the command passwd and press Enter. Ubuntu will ask you to enter your current password first — this confirms you have permission to make the change.
After you enter your current password correctly, Ubuntu prompts you to enter your new password. Type it carefully, because the characters do not appear on screen as you type. Press Enter. Ubuntu then asks you to type the new password a second time to confirm you did not make a typo. If both entries match, your password changes when ready. If they do not match, Ubuntu tells you and lets you try again.
Your new password takes effect the next time you log in. If you are already logged in, you stay logged in — you only need the new password when you log in again later.
How to change your username with usermod
Changing your username requires root access, so you will use the sudo command. Open the terminal and type:
sudo usermod -l newusername oldusername
Replace newusername with the username you want and oldusername with your current username. Press Enter and type your password when prompted. The -l flag tells usermod to change the login name. This command updates Ubuntu's user database so the system recognizes your new username.
However, this command does not rename your home directory. Your home folder still has the old name, which can cause confusion. You should rename it separately using the mv command:
sudo mv /home/oldusername /home/newusername
This moves everything in your old home directory to a new folder with your new username. After you run both commands, log out completely — click your username in the top right corner and select "Log Out" — then log back in with your new username.
What happens to your files and settings when you change your username
Your files themselves do not change. The documents, photos, and downloads in your home directory stay exactly where they are. What changes is the path to reach them: instead of /home/oldusername/Documents, the path becomes /home/newusername/Documents.
Your settings and preferences usually stay intact because they are stored in hidden configuration files inside your home directory. When you rename the home directory with the mv command, those files move along with it. Applications like Firefox, your email client, and your desktop settings should work the same way after you log back in.
The one place you may see a change is in the terminal prompt. Before the change, it showed something like oldusername@computer:~$. After you log back in, it shows newusername@computer:~$. This is just a display change and does not affect how your system works.
Changing your password if you forget it
If you forget your password and cannot log in, you can reset it using Ubuntu's recovery mode. Restart your computer and hold down the Shift key as it boots. This brings up the GRUB menu, which shows different boot options. Look for an entry that says "Advanced options for Ubuntu" and select it.
From the advanced menu, select the option that includes "(recovery mode)" in its name. Ubuntu boots into recovery mode, which gives you a root prompt without requiring a password. Type passwd username (replace username with your actual username) and press Enter. You will be asked to enter a new password twice. After you set it, type exit and select "Resume" to boot back into your normal desktop.
Recovery mode is a powerful tool because it bypasses the normal login screen. Use it only on your own computer, and only when you genuinely cannot remember your password.
Why you might want to change your username
People change their usernames for different reasons. You might have created your account with a username you no longer like, or you might want a username that matches your actual name for professional reasons. Some people change their username when they set up a new computer and want to migrate their settings from an old one.
Changing your username does not affect your security or your ability to use Ubuntu. It is purely a matter of preference. Your password is what actually protects your account, so changing your username without changing your password is safe — but if you are making changes anyway, it is a good time to update your password to something stronger.
Frequently Asked Questions
Do I need to change my password when I change my username?
No, your password and username are separate. You can change one without changing the other. However, if you are making changes to your account, it is a reasonable time to update your password as well, especially if your current password is weak or you have shared it with anyone.
What if I change my username and my programs stop working?
This is rare, but it can happen if a program has hardcoded your old username in its settings. The fix is usually to uninstall and reinstall the program, or to manually edit its configuration file to point to your new home directory. Most programs figure out your home directory automatically and do not care what your username is.
Can I change my username without using the terminal?
Ubuntu's graphical settings do not provide a way to change your username directly. You must use the terminal and the usermod command. However, you can change your password through the graphical settings by opening Settings, clicking "Users", selecting your account, and clicking the password field.
Will changing my username affect my sudo access?
No. Your sudo permissions are tied to your user account in the system files, and usermod updates those files automatically when you change your username. You will still be able to use sudo commands after the change.
What if I want to change my username back to what it was before?
You can change it back the same way you changed it the first time. Run sudo usermod -l oldusername newusername and sudo mv /home/newusername /home/oldusername. Log out and log back in, and you are back to your original username.