Ubuntu – How to change administrator username


I have accidentally typed my name wrong when I created the administrator account. Although I managed to change the user name at the login screen, I am unable to rename the /home/oldusername to /home/newusername. I tried most of the online tutorials, and it failed.

The code I tried was this:

usermod -l newusername -m -d /home/newusername oldusername

But the output is:

cannot lock /etc/passwd; try again later.

How can I fix the issue and change the folder to newusername and expect all the applications to work as before?

Best Answer

  • Login with your currentusername, open a terminal and type:

    sudo passwd root

    Enter a password for the root account, then logout, press Ctrl+Alt+F1 to open a text console, login as root (username: root, password: "the one you typed above") and run:

    usermod -l newusername -m -d /home/newusername currentusername

    Press Ctrl+Alt+F7 to return to graphic console and login as newusername.

    To change the user's display name (the one that appears at the login screen), go to System Settings -> User Accounts then click the display name on the right-hand side of the dialog.

    enter image description here

  • Related Question