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?

  • Are you running that command as root? – Seth Dec 13 '12 at 17:07
  • no in a guest account..the name i'm trying to change is the root account i guess. – Fazlan Dec 13 '12 at 17:15
  • is root and administrator different? I dnt knw – Fazlan Dec 13 '12 at 17:15
  • hey I don't understand have u access to admin/root account?? – hingev Dec 13 '12 at 17:18
  • 1
    You cannot use the guest account to do any administrative tasks. – user68186 Dec 13 '12 at 18:10

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

| improve this answer | |
  • it says user oldname is currently logged in – Fazlan Dec 13 '12 at 17:54
  • Answer updated. – Eric Carvalho Dec 13 '12 at 19:58
  • I followed your instructions and indeed the user name was changed. If I look with Nautilus at Computer -> Home I see only the new user name. What is still strange is when I boot from a shutdown, the original user name still comes up at the login stage. Where is the original name still stored? – Ilan Nov 8 '15 at 8:18
  • @Ilan answer updated. – Eric Carvalho Nov 8 '15 at 20:46
  • Ctrl+Alt+F1 doesn't work – June Wang Aug 1 at 7:08

You need to do this from recovery mode.

Reboot, choose recovery mode, and then drop to a root console and type the command there. Then reboot again as normal.

| improve this answer | |

The first simple solution that you can do is to create a new user with the right username that you want and add it to the administrator group: /etc/sudoers

other way, you can do that with your old username (I tested it on fedora):

# usermod -l new-username old-unername
| improve this answer | |
  • 1
    You may need to add sudo before that line like sudo usermod -l new-username old-unername, in Ubuntu. – user68186 Dec 13 '12 at 18:13
  • The username is changed but the folder name is still the old name – Fazlan Dec 22 '12 at 15:11
  • #: means you have the root permissions, and $: means you're just a simple user. – Boubakr Aug 27 '13 at 15:35

I would create a new account, and copy all of your files across. This is probably the most idiot-proof method.

| improve this answer | |

Changing usernames will cause unavoidable problems. A lot of programs will try to read and write data from the old directory that's no longer there. Creating a new account and copying over all the old folders seems like a good idea. I believe there are other problems.

But this answers the question where the previous comments did not help me.

Simply logging back in as as root may not work because my old username had active processes. So I did like other's have said and rebooted into recovery mode. But then I got the error message the original poster mentions. As discovered here this is because the drive is read only in recovery mode so you have to make it read-write.

Summary fix:

sudo passwd root # assign a password
reboot  # into recovery mode and log in as root

Hold shift during boot if your grub menu is not set to show. Log in as root and get to shell.

mount -o remount,rw /  # make the disk writable
usermod -l <newname> -d /home/<newname> -m <oldname>
passwd -l root   #  deactivate the root password

Your old username will be the login name, but it will still let you in. To correct it, edit the file with the command below and look for the line that has your new and old username on the same line and change the old one to the new one:

sudo nano /etc/passwd

As others have said in other places, expect problems when changing your username as many programs will try to do things like find or store application data in your old username's folder which isn't there anymore.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.