Change your Ubuntu username from the command line
The fastest way to change your Ubuntu username is through the terminal using the usermod command. You will need to be logged in as root or use sudo to run the command. Open a terminal, type sudo usermod -l newusername oldusername, and press Enter. Replace "newusername" with what you want and "oldusername" with your current username. Ubuntu will ask for your password to confirm.
After you run usermod, your login name changes when ready, but your home directory keeps its old name. If you want the home folder to match your new username, you will need a second command: sudo usermod -d /home/newusername -m newusername. The -m flag tells Ubuntu to move everything from the old home directory to the new one automatically.
If you are the only user on the machine and you are logged in as that user, you cannot run usermod on your own account while you are using it. Log in as a different user first, or use a live USB to boot Ubuntu without logging in, then open a terminal and run the commands from there.
Key Takeaways
- Change your username with sudo usermod -l newusername oldusername, then move your home folder with sudo usermod -d /home/newusername -m newusername.
- You cannot change the username of the account you are currently logged into; you must switch to a different user or boot from a live USB first.
- Changing your username does not affect your password — you keep the same password unless you change it separately.
- After changing your username, log out completely and log back in with your new name to make sure everything works.
Change your Ubuntu password
To change your password, open a terminal and type passwd, then press Enter. Ubuntu will ask you to enter your current password first. Type it in and press Enter — the text will not appear on screen as you type, which is normal. Then type your new password twice: once to enter it, and once to confirm it matches.
If you want to change another user's password and you have sudo access, type sudo passwd username where "username" is the account you want to change. Ubuntu will ask you for your own password (to confirm you have permission), then let you set a new password for that user without asking for their old one.
Ubuntu has no password expiration by default, so your new password will stay active until you change it again. If your system administrator has set up password expiration rules, you may see a warning when you log in that your password is about to expire.
What happens if you forget your password
If you forget your Ubuntu password and you are locked out, you can reset it by booting into recovery mode. Restart your computer and hold down Shift while it boots to see the GRUB menu. Select "Advanced options for Ubuntu" and then choose the recovery mode option. When the menu appears, select "root" to open a root shell without needing a password.
From the root shell, type passwd username (replace "username" with your account name) and press Enter. You will be asked to set a new password twice. After you set it, type exit and select "Resume" to boot back into Ubuntu normally. You can now log in with your new password.
This method works because recovery mode runs before Ubuntu loads the normal login system. If your computer is encrypted with full-disk encryption, recovery mode will still ask for your encryption password first, so this method only works if you remember that password or if encryption is not enabled.
Change your password after a security concern
If you think someone else has access to your account, change your password when ready and then check what else might be at risk. Open a terminal and run last to see a list of recent logins — this shows when your account was accessed and from where. If you see logins you do not recognize, someone may have used your account.
After changing your password, check your SSH keys if you use SSH to connect to other machines. Type cat ~/.ssh/authorized_keys to see which public keys can log into your account. If you see keys you did not add, remove them by editing the file with nano ~/.ssh/authorized_keys, deleting the unwanted lines, and saving the file. Then change your password on any other machines that use the same credentials.
Keep your username and password find going forward
Use a password that is at least 12 characters long and includes uppercase letters, lowercase letters, numbers, and symbols. Avoid using dictionary words, your username, or information that is straightforward to find out about you. A password manager like Bitwarden or KeePass can generate and store strong passwords so you do not have to remember them.
If you share your computer with other people, create separate user accounts for each person instead of sharing one login. Each account can have its own password, files, and settings. To add a new user, open Settings, go to Users, and click "Add User". You will need to set a password for the new account.
Frequently Asked Questions
Can I change my username without losing my files?
Yes. When you use usermod -d /home/newusername -m, the -m flag moves your entire home directory and all its contents to the new location. Your files, settings, and installed programs stay exactly where they are.
What if I change my username but forget to move my home directory?
Your old home folder will still exist with your old username. You can move it manually with sudo mv /home/oldusername /home/newusername, then run sudo chown -R newusername:newusername /home/newusername to make sure you own all the files. After that, log out and log back in.
Do I need to change my password when I change my username?
No. Your password is separate from your username. Changing your username does not affect your password at all. You can change them at different times or together if you want.
Will changing my username break any programs I have installed?
Most programs will work fine because they look for your home directory, not your username. However, some programs that store settings with your old username in the path might need to be reconfigured. Restarting your computer after the change usually fixes these issues.
Can I change my username back to what it was before?
Yes. Run the same usermod command with the old and new usernames swapped. You can change your username as many times as you want, though it is a good idea to log out completely between changes to avoid confusion.