how to change username on ubuntu

The Right Way To Change A Username On Ubuntu (GUI/Terminal)

Changing the username on a computer might seem like a simple task, but it’s not. There isn’t an easy way to do it, and it comes with many implications we might not necessarily think about (permissions change, for example). Let me give you the step-by-step procedure to do this the right way on Ubuntu.

The only way to change a username on Ubuntu is to do it from a terminal, using the “usermod” command. The permissions, home folder name and group must also be updated manually after that.

Don’t worry, I’ll explain every step of this process in detail. But first, let’s start with the prerequisites and the traps that you’ll want to avoid while doing this.

Want the best experience? Become a premium member for ad-free browsing, access exclusive content, and ask questions in our private forums. Your membership helps support the site!
Linux doesn’t have to be intimidating. With my e-book, Master Linux Commands, you’ll uncover the secrets of the terminal in a fun, step-by-step journey. From basics to scripts, get ready to level up your Linux skills. Oh, and did I mention the handy cheat sheet you get as a bonus?


Changing a username on a Linux operating system is not risk-free. There are a few things you should consider before following this procedure.

Know the risks

The username you use on Linux is not only used for the login process but it’s also tied to a few other things on your system:

  • Permissions: each file and folder has permissions tied to an owner and a group.

    If you switch to another user, you have to make sure the permissions are updated accordingly.
  • Home folder: the home folder is also linked to your username (/home/<user>).
    If you simply create a new username, you’ll lose access to all its content.
  • Services configuration: you may also have some applications and services running on your system that are using the current username, giving it permissions or storing data in the home folder.
    You’ll need to update them to use the new username.

Considering this, it’s a good idea to start this procedure by creating a full backup of your system, especially the home folder.

Create a backup of the user’s data

While changing the username, the permissions will be updated and the home folder will be renamed. To avoid any data loss, it’s a good practice to start by doing a full backup of the critical data you might have on your system.

It won’t take long and it can save you if anything wrong happens during the process. Try to at least copy the important files to another computer (or an external drive), so you can recover them easily if something happens.

I have an article on this website explaining several ways to back up a Raspberry Pi. I recommended reading it if you need help to do this carefully (even if you are not using a Raspberry Pi, it’s the same commands & tools on Ubuntu).

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Use an administrator account

By default, there is only one user active on the Ubuntu system, the one you are currently using. But it’s not possible to change the username while logged in with it.

So, the first step is to have another account available, with administrator permissions, so you can change the main user’s name while you are using this one.

The procedure to create one is different depending on whether you have access to a desktop interface or not (SSH or Ubuntu Server). The instructions to follow in both cases are explained below.

If you use Ubuntu Server or SSH from another computer:

The easiest way will be to create a new user and follow the tutorial via SSH, so you can copy and paste the commands I give you later. But in any case, you need to create a new user with sudo access:

I explain everything in this article: How to Create a New User.
But in short, you can do it from an administrator account with:
sudo adduser <newuser>
sudo adduser <newuser> sudo

Then use this new user to connect via SSH, and follow the procedure below.

Warning: You can’t change the username by using sudo with the user you want to rename. I tried it, but even when you switch to the root account in your SSH session, the current user is still active, so it won’t work.

If you use the desktop interface

If you want to use the desktop interface, then you need to create a temporary account first:

  • Open the system settings.
  • Go into “Users” in the left menu.
  • Click on “Unlock” to get full access to the users settings.

    Enter your password when asked.
  • You now have access to the “Add User…” button at the bottom of the screen:
  • Follow the instructions to create the new user:

    Make sure to make it an administrator and set the password.

That’s it, remember the username and password, as we’ll use them later.
You can move to the next part to change the username.

How to change the username on Ubuntu

The only way to change a username on Ubuntu is to use the command line. If you are doing this from Ubuntu Desktop, make sure to follow the steps below to switch to another account, or use SSH with an administrator account and directly type the commands.

Desktop interface

If you want to do this procedure from the desktop environment, here are the first steps you need to follow:

  • Log out, and log in with the temporary account we just created.
    You need an administrator account that is different from the user you intend to rename.
    Aside from that, it doesn’t matter which account you are using.
  • Open a terminal.
  • Follow the command lines given in the next section.

There is no way to change the username from the settings. You can change the display name, but it won’t change the real username. The only way I have found is to do it in command lines.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Command lines

Please check this full guide on how to switch users on Ubuntu for more details, but here is there short version.

If you do this via SSH, make sure the session you’ll rename is closed on the computer. It’s not possible to rename a user who is logged in or has services running.

You can switch to root if you like, this way you don’t have to use sudo in each of the commands below. But it’s not mandatory. You can switch to root with:
sudo su

Please read this article for more details on how to use root on Ubuntu servers.

Whatever the option, you must now be connected to a terminal, with a different account than the one you want to rename, and with administrator permissions (sudo access or using root).

Type this command to rename the user:
sudo usermod -l <new_user> <old_user>
In my example, the old user is “rpitips”, the new one will be “raspberry”, so I use:
sudo usermod -l raspberry rpitips

Obviously, you don’t need sudo if you are logged in as root.

The home directory will keep the old name, but the permissions will be given to the new one. There is no need to change it, but I’ll explain how to do it later.

I also recommend changing the group name associated with the user, you can do this with:
sudo groupmod -n raspberry rpitips

This way, you have the correct permissions on the home folder:

Finally, if you want to change the home directory name, the proper way to do it is to use usermod again:
sudo usermod -d /home/<new-user> <new-user>
So, in my example:
sudo usermod -d /home/raspberry raspberry
Yes, we don’t specify the path to the existing folder, it’ll find it automatically.

You can now log out and log in with the new username.
If the new user isn’t listed on the desktop login screen, click on “Not listed?” and type it for the first login.

If everything went well, you should get back to the same session, with all your files and settings the same way as previously (and if there is any issue, that’s why we created a backup earlier!).

If you’re new to the Linux command line, this article will give you the most important Linux commands to know, plus a free downloadable cheat sheet to keep handy.

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

Things to consider after changing the username

If you only use Ubuntu for basic use with a desktop interface, everything should work correctly, as if you were still using the old username. The permissions should update automatically (it’s using the user ID in most cases, it didn’t change) and your home folder should still be there.

But if you experience any issues, you might look for things that haven’t been updated. It can be:

  • Permission issues: most likely because some applications or services are still creating new files with the old username.
  • Configuration issues: maybe you have some application with the old username or home folder path in the configuration. You need to update the configuration files.
    For example, if you have a downloader tool saving files into /home/<olduser> it won’t work anymore.

So, it might take a few days to fix all the potential issues, even for typical desktop usage. But it shouldn’t be that complicated. However, if you host critical services, you probably need to take some time to investigate in advance and conduct a mini-audit of the configuration files and potential issues before changing the username or quickly afterward.

I hope this tutorial helped you, and if you are a casual Ubuntu user, you’ll find many other interesting tutorials on this website, here are a few examples:

Your Go-To Linux Command Reference!
Download your exclusive free PDF containing the most useful Linux commands to elevate your skills!
Download now

🛠 This tutorial doesn't work anymore? Report the issue here, so that I can update it!

Reminder: Remember that all the members of my community get access to this website without ads, exclusive courses and much more. You can become part of this community for as little as $5 per month & get all the benefits immediately.

Additional Resources

Overwhelmed with Linux commands?
My e-book, “Master Linux Commands”, is your essential guide to mastering the terminal. Get practical tips, real-world examples, and a bonus cheat sheet to keep by your side.
Grab your copy now.

VIP Community
If you just want to hang out with me and other Linux fans, you can also join the community. I share exclusive tutorials and behind-the-scenes content there. Premium members can also visit the website without ads.
More details here.

Need help building something with Python?
Python is a great language to get started with programming on any Linux computer.
Learn the essentials, step-by-step, without losing time understanding useless concepts.
Get the e-book now.

Similar Posts