What you need to know before you start

Changing your username in Ubuntu requires you to log in as a different user — you cannot rename the account you are currently using. The simplest approach is to create a new user account with the name you want, transfer your files to it, and delete the old account. Changing your hostname (the name your computer shows on the network) is separate and simpler — you edit one configuration file and restart.

Both changes take about 15 minutes if you follow the steps in order. You will need to open a terminal and type commands, but each one is provided exactly as it should appear. If a command fails, the error message will usually tell you what went wrong.

Key Takeaways

  • You cannot rename your current user account directly; instead, create a new account with your desired username and transfer your files to it.
  • Changing your hostname requires editing the /etc/hostname file and the /etc/hosts file, then restarting your computer.
  • Before deleting your old user account, make sure all your files have been moved to the new account and you have logged in successfully at least once.
  • If you are the only user on the system, you may need to create a temporary admin account first to perform the username change.

Creating a new user account with your desired username

Open a terminal by pressing Ctrl+Alt+T. Type the following command, replacing newusername with the name you want:

sudo adduser newusername

The system will ask you to create a password for this new account. Type it twice when prompted. You will then be asked for the user's full name, room number, work phone, home phone, and other information — you can leave all of these blank by pressing Enter, or fill them in if you want. When you see the prompt asking "Is the information correct?", type y and press Enter.

The new account is now created, but it does not have administrator privileges yet. Type this command to add it to the sudo group (which allows it to run commands that need elevated permissions):

sudo usermod -aG sudo newusername

You will be asked for your current password. Type it and press Enter. The new user is now ready to use.

Moving your files to the new account

Before you delete your old account, you need to copy all your personal files to the new one. In the terminal, type:

sudo cp -r /home/oldusername /home/newusername/oldfiles

Replace oldusername with your current username. This command copies your entire home directory into a folder called oldfiles inside the new account's home directory. The sudo prefix is necessary because you need permission to access the old account's files.

Next, make sure the new account owns these files. Type:

sudo chown -R newusername:newusername /home/newusername/oldfiles

This changes the owner of all the copied files from your old account to your new one. Without this step, you may not be able to open or edit them.

Logging in with your new account

Log out of your current session by clicking the power icon in the top-right corner and selecting "Log Out". At the login screen, click on your new username and enter the password you created. Once you are logged in, open the file manager and navigate to the oldfiles folder to confirm your documents, photos, and other files are there.

If you use Firefox, Thunderbird, or other applications that store settings in hidden folders, those settings will be in the oldfiles folder as well. You can copy individual process folders (like .config or .mozilla) from oldfiles to your new home directory if you want to preserve those settings. Open a terminal in your new account and type:

cp -r ~/oldfiles/.config ~/ && cp -r ~/oldfiles/.mozilla ~/

This copies the configuration folders for most common applications. Adjust the folder names if you use different software.

Deleting your old user account

Once you have confirmed that all your files are accessible in the new account, you can remove the old one. Open a terminal and type:

sudo deluser --remove-home oldusername

Replace oldusername with your original username. The --remove-home flag deletes the entire home directory for that account, freeing up disk space. The system will ask for your password; type it and press Enter. The old account and all its files are now gone.

If you want to keep the old account's files for backup purposes, omit the --remove-home flag. The account will be deleted but the files will remain in /home/oldusername until you manually delete them later.

Changing your hostname

Your hostname is the name your computer displays on the network and in the terminal prompt. To change it, open a terminal and type:

sudo nano /etc/hostname

The nano text editor will open with the current hostname displayed. Delete the existing text and type your new hostname. Hostnames must contain only letters, numbers, and hyphens — no spaces or special characters. Press Ctrl+O to save, then press Enter to confirm the filename. Press Ctrl+X to exit the editor.

Next, you need to update the /etc/hosts file to match. Type:

sudo nano /etc/hosts

Look for a line that contains your old hostname (usually near the top of the file, after lines starting with 127.0.0.1 and ::1). Replace the old hostname with your new one. Save and exit the same way: Ctrl+O, Enter, Ctrl+X.

Restart your computer by typing:

sudo reboot

When your computer starts up again, open a terminal and type hostname to confirm the change took effect.

Troubleshooting common problems

If you see a "permission denied" error when copying files, make sure you are using sudo at the start of the command. If the new account cannot access the copied files, run the chown command again to reset ownership.

If you cannot log in to the new account, restart your computer and try again. Sometimes the system needs to refresh its user database. If the password prompt keeps rejecting your password, make sure Caps Lock is off and that you typed the password correctly when you created the account.

If the hostname change does not take effect after restarting, check that you edited both /etc/hostname and /etc/hosts. Some systems also require you to update the hostname in the network settings through the graphical interface — open Settings, go to Details, and look for a Hostname field.

Frequently Asked Questions

Can I change my username without creating a new account?

No. Ubuntu does not allow renaming a user account that is currently in use. Creating a new account and transferring files is the standard method. Some advanced users edit system files directly, but this often causes permission problems and is not recommended.

What if I am the only user on the system?

You will need to create a temporary administrator account first, log in as that account, and then create your new permanent account and delete the old one. Follow the steps above using the temporary account to perform the deletion.

Will changing my username affect my installed programs?

Most programs will work fine because they are installed system-wide, not in your user folder. However, programs that store settings in your home directory may need to be reconfigured. Copying your configuration folders (as described in the "Moving your files" section) usually preserves these settings.

Do I need to change both my username and hostname?

No. They are completely separate. Your username is your login account; your hostname is your computer's network name. You can change one, both, or neither depending on what you need.

What happens to my files if I delete the old account without copying them first?

If you use the --remove-home flag, the files are permanently deleted and cannot be recovered. Always copy your files to the new account and verify they are there before deleting the old one.