+8 votes
in Linux by (26.3k points)
How to change Ubuntu username?

1 Answer

+20 votes
by (26.3k points)
Best answer

How to change the identifier of a user account?

Most user account information in Ubuntu is editable from the graphical Users and Groups administration tool . For example, an account's display name, password, phone number, or home folder location can be changed through this GUI.

However, the identifier of an account (in English, login name ) cannot be modified through a graphical tool. The use of the command line tool usermodis required.


Using usermod

Like all command line administration tools, usermodis a powerful tool that has a strict structure. If you violate this structure, you can render a user account inoperative.

The command is used as follows:

sudo usermod [options] IDENTIFIER

A few options must be passed to in usermodorder for them to have an interesting result. Below is an example of a complete command that causes an account identifier to be changed and its home folder to be moved:

sudo usermod --login new_username --home new_home_folder_location --move-home current_username

Let's take a look at this command and its options:

  • The --login option specifies the new identifier that should be assigned to the user account. This is the only option that is required to be provided;

  • (Optional) The --home option specifies the location of the user's home folder. If this option is not specified, the current home folder location is retained;

  • (Optional) The --move-home option moves the contents of the current home folder to the new location, set with the --home option . If this option is not specified, the new home folder for the account will be empty;

  • the term current_identifier designates the name of the account whose identifier must be changed.

Additional options for usermodare available. Consult the user manual of usermod( man usermod) for more information.

Example: User a wants to change the name of user dd to user xx

a @ a:~$ sudo usermod --login xx   --home  / home / xx   --move-home  dd 



  1. The identifier of a user account cannot be modified when a session is opened with this account;

  2. Only an administrator or the superuser account can modify the identifier of a user account.

Let's illustrate these limitations with a concrete example: in a computer, two user accounts exist: administrateurand utilisateur. The user account administrateuris the only one with administrative rights.

  • utilisateurcannot change anyone's ID;

  • administrateurcan modify the identifier of utilisateur;

  • administrateurcannot modify its own identifier. To proceed with the modification of its identifier, it is necessary to go through a superuser session (root) in recovery mode .


Practical examples

Robert and Denise have a computer with an Ubuntu system installed. The system was delivered to them as follows:

  • Robert has an account whose identifier is administrateur. The account administrateuris the only account with administrative rights;

  • Denise has an account with the username utilisateur.

Robert and Denise would like their user account to have their first name ( robertand denise) as their identifier. Also, they would like their home folder to be moved so that they reflect an appropriate location ( /home/robert/and /home/denise/). How to proceed ?


Changing the ID of a user account from another administrator account

  1. Denise must not have an active current session. If so, it must first close all of its sessions;

  2. Robert logs in with his account administrateur;

  3. In a terminal, Robert executes the following commands:

admin@computer:~$ sudo pkill -u user 
admin@computer:~$ sudo usermod --login denise --home /home/denise --move-home user

Now Denise's account ID is deniseand her home folder is located at /home/denise/.


Change the identifier of the only administrator account of an Ubuntu system

Robert must not have an active session in progress. He cannot change his user account identifier himself. Also, Denise is not a system administrator; therefore, she cannot modify Robert's account identifier. To change Robert's account ID, it is necessary to go through a recovery mode superuser session .

  1. Robert restarts the computer;

  2. At the load menu, he chooses the menu entry Ubuntu, kernel 2.6.x (recovery mode);

  3. When a context menu appears, he chooses the root option to open a session in superuser mode;

  4. At the command prompt that appears, Robert runs the following commands:

    1. mount -o remount,rw /

      to be able to write to the file system

    2. root@computer:~# usermod --login robert --home /home/robert --move-home administrator


  5. Then Robert executes the following command:
    root@computer:~# exit

    The superuser session ends and the context menu appears again;

  6. He chooses the resume option to continue loading Ubuntu normally.

Now Robert's account ID is robertand his home folder is located at /home/robert/.


Addendum: groupmod to change user group names

When creating a new user account, a new user group with the same name is automatically created. This group becomes the primary group for the new user account. When you modify the identifier of a user account with usermod, the name of the associated group is not automatically modified. To force a user group name to be changed, you must use the command line utility groupmod.

Let's go back to the previous example of Robert and Denise's computer: when they received their computer, two accounts were created: administrator was a member of a user group of the same name ( administrator ), and user was also a member of a group of the same name ( user ). Robert and Denise renamed their user accounts with usermod(the admin account became robert and the user account became denise ). However, the names of the user groups have not changed: the user groupand denise 's is user .

In itself, this has no real impact: Ubuntu uses a numerical identifier to identify the user owners and the groups that own the files contained in the operating system, the names of the user accounts and groups of users may differ. However, for more cleanliness and to be in agreement with certain tutorials, it is preferable that both are identical.

To do this, use the command line utility groupmod. It must be run by a system administrator; current sessions do not have to be closed. The command is used as follows:

admin@computer:~$ sudo groupmod --new-name new_name current_name

Let's take a look at this command and its options:

  • The --new-name option specifies the new name that should be assigned to the user group. The name will be replaced by new_name ;

  • the term current_name designates the name of the group whose name is to be changed.

For example, once their IDs have been changed, Robert and Denise want their primary groups to match their name as well.

  1. Robert logs in with his account administrateur;

  2. In a terminal, Robert runs the following two commands:
    robert@computer:~$ sudo groupmod --new-name denise user 
    robert@computer:~$ sudo groupmod --new-name robert administrator

Now the names of the main groups utilisateurand administrateurare deniseand robert. The modification is taken into account immediately for all user sessions, even for Robert's session which is currently in progress.


See as well


1) If you get the error "could not lock /etc/passwd", the files are probably read-only. In this case, run

root@computer:~# mount -o remount,rw /

and redo the previous command.

Ask a Question
Welcome to WikiTechSolutions where you can ask questions and receive answers from other members of the community.

You can ask a question without registration.