Change username in ubuntu 12.04

Below tutorial will show you how to change username in ubuntu 12.04 precise.First,we need login as root the change the username,then restart the enable this changing ,here we go.

1.Open a terminal by Pressing Ctl+Alt+t or search terminal in Dash

2.Unlock account root and enable login as root using below command

sudo passwd root
sudo sh -c 'echo "greeter-show-manual-login=true" >> /etc/lightdm/lightdm.conf'

3.Reboot your computer and login as  root

4.Open a terminal and Use blow command to change your username

usermod  -l newname oldname

5.(Optional)Now you already changed your username,but your home folder name still are “/home/oldname”,if you also want to change /home/oldname to /home/newname just run below command

usermod -m -d /home/newname newname

Note:Of course you can combine step 4 and step 5 using below command

usermod -m -d /home/newname -l newname oldname

6.All done,use below command to lock your root again,then you can reboot and login as your new username

passwd -l root

18 thoughts on “Change username in ubuntu 12.04

      1. apm

        Hi. Yes, i followed all steps above and after reboot tried to login using standard GUI way. System just turns screen off (to the black) and then returns back to the login screen. In result, I decided to rename everything back, so working under old username..

        1. boomer

          I had the same problem as you. In my case it was caused by the fact that I was using an encrypted home directory, and the ecryptfs stuff wasn’t getting updated properly. I see your post is a bit old, but maybe you’re still interested in the solution I found. The following steps fixed the problem for me.

          1. At the login screen, press CTRL + ALT + F1 to get a console. Login at this console with your new user credentials.

          2. Ensure that you are in the new user’s home directory by doing a “pwd” command, which should yield “/home/newuser”. Now do an “ls -al” to see all the files in the directory. Don’t leave out the “-a” flag, or you won’t see the hidden files.

          3. You should see two symlinks called “.ecryptfs” and “.Private”, which still point to their old respective subfolders in “/home/.ecryptfs/oldname/”. Delete these two symlinks (sudo needed), then create new symlinks using “sudo ln -s ” for the paths “/home/.ecryptfs/newname/.ecryptfs/” and “/home/.ecryptfs/newname/.Private/”.

          4. Ensure that the above worked by doing another “ls -al” and checking the targets of the symlinks. You should see the following files (hope the layout will be readable, don’t know how to do code tags on this board):

          Access-Your-Private-Data.desktop -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.desktop
          .ecryptfs -> /home/.ecryptfs/newname/.ecryptfs/
          .Private -> /home/.ecryptfs/newname/.Private/
          README.txt -> /usr/share/ecryptfs-utils/ecryptfs-mount-private.txt

          5. If you see the above files, and the symlinks point to the right places, all that’s left is to edit the file “/home/.ecryptfs/newname/.ecryptfs/Private.mnt” (with sudo privileges). It should contain a single line with the path to the old username’s directory. Change this to the new username’s directory.

          6. You’re done. Reboot the system, and you should be able to do a GUI login again.

          7. (optional) After you’re logged in again, you may want to also change the old groupname to a new one by doing “groupmod -n newgroup oldgroup”, where oldgroup is probably equal to your old username. Also, you may want to do “usermod -c “Real Name” newname” to also update the real name of your new user (which is shown at the login screen etc.).

          Hope this helps, even if it is a little late.

  1. 2ls

    Excuse my English it is not very good

    I noticed that this an old post but I’m having trouble with downloading software from ubuntu it just says querrying software sources nad when I try to use apt-get it says I have to be logged in as “super user”. I’m using Ubuntu 12.04 for amd64. I followed the steps you showed above and when I restart my computer it logs me in as it usually does, no log in screen to choose if I want to login as root or as normal user. What other method is there to get root control over my system?

    1. Admin Post author


      Seems your problem is permission related,nothing to do with changing username.
      You can use command “groups” to verify if you have joined the “sudo” group.
      If you already joined group sudo ,please let me know the detail error messages,thanks

  2. annie

    Hi, i followed the instructions, but after the “usermod -m -d /home/newname -l newname oldname” command i see “usermod: cannot lock /etc/passwd; try again later.” what should i do?

    1. http://www./

      I agree with all of them except for the part about knowing HTML/CSS. Maybe I disagree because I do both design and implementation but I think it’s important to know what is possible. It’s not that hard to keep up with. We can do quite a bit with CSS today but it’s not a total free for all. Designers should know what the limits are because it helps manage expectations and makes it that much easier for front end developers.

  3. makara

    So I did this.
    sudo sh -c ‘echo “greeter-show-manual-login=true” >> /etc/lightdm/lightdm.conf’
    did nothing. If you’ve got autologin, just restart, and when it logs in as old, log out and log in as root.

    What broke:
    -Desktop background.
    -Clementine library paths and xspf playlists broke. RhythmBox also broke, but will accept “file://~/Music”.
    -Dropbox needs relinking.
    -Transmission torrents broke. Need to ‘set location’ for all files and change the default directory.
    -My pinned PDF on Docky disappear and also custom .desktop files need fixing.
    -VirtualBox forgot my machines.
    -Calibre library.
    -LibreOffice history.
    locate db index
    custom eXistdb install

    Histories and pinned documents lost.
    The rest are fixed fairly easily.


Leave a Reply

Your email address will not be published. Required fields are marked *