Sep 23, 2023 4 min read

How to Change Username on Debian 11

Change Username on Debian 11 with our step-by-step tutorial. The username is the first required field during Debian OS installation.

Change Username on Debian 11
Table of Contents

Introduction

Before we begin talking about how to change username on Debian 11, let's briefly understand – What is a username?

The username is the first field you must fill out while installing the Debian operating system on your device. However, you could decide to modify your username later on if you don't like it. On Debian, their username uniquely identifies each user.

Changing your username on Debian 11 is a simple process that can be done through the usermod command in the terminal, granting you flexibility and control over your account's identity.

In this tutorial, you will change username on Debian 11. We will also address a few FAQs on how to change username on Debian 11.

Change Username on Debian 11 Bullseye via Command Line

It should be noted that under Debian, a user's existing username cannot be changed. Nevertheless, you may change the current username by making a temporary user, logging in as that user, and making the necessary changes.

For instance, if you already have a username with the "user1" ID, you will need to create "user2" and log in as that user. After that, you can modify user1's username.

Follow the command below to create a new user on Debian:

sudo adduser mainuser

Give this user sudo privileges using the following command after creating the user:

sudo usermod -aG sudo mainuser

Displaying the list of all users will now allow you to confirm the user. To retrieve a list of all users on Linux, use the command line:

cut -d: -f1 /etc/passwd

Change Username on Debian 11 Bullseye

On Debian 11, you can change your username from:

  • Terminal
  • GUI

1) Change Username on Debian from Terminal

On Debian, changing the username from the terminal has two options:

  • Using the usermod Command
  • Using the sed Command

a) Change Username on Debian from Terminal Using usermod Command

Check to see whether the username hasn't already logged into the system. The usermod command can be used to change the name. The user's name will be changed from their previous name to their current name:

sudo usermod -l <newname> <oldname>

In the example given below, I'm replacing the temporary user I created with the name of mainuser to the zainab:

sudo usermod -l zainab mainuser

By running the command to display the list of users, you may determine whether the name has changed or not:

b) Change Username on Debian from Terminal Using sed Command

Use the following command to launch the terminal and change to the root:

sudo su

Next, provide the old and new names for the account's username. The command's general syntax is as follows:

sed -i s/<old_user>/<new_user>/g /etc/passwd

Let's use the following command to switch the username zainab to linux2:

sed -i s/zainab/linux2/g /etc/passwd

The new name will appear on the lock screen once you run the command and restart the computer:

Change Username on Debian 11 Bullseye via GUI

The GUI is the next simplest method for changing the username on a Debian system. Open the device's settings from Activities:

When you select Users from the left panel in the device settings, a list of users will appear on the right side of the screen. To make changes to the device, you must first input the password:

By selecting the pencil icon in the following image, I am changing the username of Linux2 to zainab:

The username has successfully been modified:

FAQs to Change Username on Debian 11

Is it recommended to change the username frequently? 

Changing your username frequently is not necessary unless there are specific security concerns that warrant a change. It is more important to choose a strong password and follow other security best practices to protect your user account.

Do I need root privileges to change the username? 

Yes, you need administrative privileges to change the username. Either log in as the root user or use the sudo command before the usermod command.

Can I change my username while logged into the current user? 

No, you cannot change your username while you are logged in as the user you want to modify. Log in as a different user with administrative privileges to change the username.

Will changing my username affect my files and settings? 

Changing the username will not impact your files and settings. However, it is always recommended to create a backup before making any modifications.

Can I use any username I want? 

There are certain restrictions when choosing a username. It should be unique, not exceed the maximum length allowed (usually 32 characters), and adhere to specific character limitations (typically alphanumeric characters and underscores).

Can I change the username for the root user? 

Yes, you can change the username for the root user using the same usermod command. Note that changing the root username should be done with caution as it can affect system functionality.

Is it possible to change a username for a different user account? 

Yes, the usermod command can change the username for any user account on the system, including those created by other users.

Conclusion

While choosing a username for your Debian system, errors may occur, but you can fix them. To modify the current username on Debian, use the usermod command. To change the username on Debian, you must first establish a temporary account with sudo privileges so that the current user's username can be changed.

If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.

Great! You’ve successfully signed up.
Welcome back! You've successfully signed in.
You've successfully subscribed to DevOps Blog - VegaStack.
Your link has expired.
Success! Check your email for magic link to sign-in.
Success! Your billing info has been updated.
Your billing was not updated.