I made a mistake in the username at the time of installation. So I changed the name of the user after logging in by creating a guest account with SUDO rights. But when I checked the list of users using ls /home command I am not seeing the new name for the user instead Old name is appearing. But I use the new name to login.

Is it like I need to change the name inside Home directory separately? Also , if there is any other changes needs to be done .. ?

share|improve this question

Procedure to rename or change username in Ubuntu:

If running as the user to be modified, logout first, then open a console:

Press Ctrl+Alt+F1

Otherwise, simply open a new Terminal:

Press Ctrl+Alt+T

And run:

exec sudo -i
killall -u oldname
id oldname
usermod -l newname oldname
groupmod -n newname oldname
usermod -d /home/newname -m newname
usermod -c "New_real_name" newname
id newname

Example:

sudo -i
killall -u belaje
id belaje
uid=1000(belaje) gid=1000(belaje) groups=1000(belaje),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),109(lpadmin),127(sambashare)
usermod -l  balaja belaje
groupmod -n balaja belaje
usermod -d /home/balaja -m  balaja
usermod -c "Bala Jagannathan" balaja
id balaja

Whenever you want to get back from console version to graphical version:

Press Ctrl+Alt+F7

share|improve this answer
    
Using this procedure I successfully modified user account however only from another account (which I had to create for that purpose and later deleted). I wonder if that is the case (which is not mentioned actually) or I was doing something wrong? The main point was that "killall -u oldname" logged me out so that I couldn't continue remaining steps. – baltasvejas Oct 3 '15 at 7:20
1  
This probably would be better done through a TTY, not a terminal emulator in GUI. So I'd replace the keyboard shortcut to terminal emulator with shortcut to TTY1, which is Ctrl + Alt + F1 – Sergiy Kolodyazhnyy Oct 6 '15 at 17:45
1  
Please add that if the user has an encrypted home directory, it's also necessary to edit /home/newname/.ecryptfs/Private.mnt to point to the new home directory. – Shaun Dychko Nov 6 '16 at 20:09
    
Does not really work for me. After doing this, the ui does not work properly anymore. After login it just shows the desktop wallpaper. – Johannes Dec 12 '17 at 9:32

on the server this worked for me:

sudo usermod -md /home/NewHome -l NewName OldName
sudo groupmod -n NewGroupName OldGroupName

This renames the user and its group and also the home folder.

share|improve this answer

This works, but a lot of the apps will break because they specifically call for the /home/oldusername; many individual software authors don't use variables to call their configs, they directly specify oldusername not $HOME. Chrome, GTK and firefox break like this. Don't forget your keyrings will have the old credentials as well... I'm not sure how to back those up.... maybe export them?

So, I end up doing the following to change username - man i wish i knew an easier way.

  • as olduser, sign in to chrome and firefox to sync out the settings
  • using users and groups in Settings, create user killmenow with pass of same, make him admin, reboot and log in as killmenow.
  • open terminal, riun sudo i, then mkdir /home/newusername and making it the same uid:gid as the oldusername
  • Move usercreatedfiles.xyz, Desktop, Downloads, and other dirs containing created files like docs, pics, music, movies, etc in /home/oldusername/ to /home/newusername.
  • Find out any specific apps with particular settings... Helpful to pay attention here :) user will likely bean you with a phonebook if you lose their files ;)
  • vi /etc/passwd and /etc/group to reference newusername and /home/newusername
  • passwd newusername and enter a temporary password twice reboot and log in as newusername, password being what you entered in the previous point.
  • delete killmenow using "users and groups" in Settings.

wait until some time passes before deleting /home/oldusername - in case you missed important stuff... or move it to /home/newusername/Downloads and tell them

mv /home/oldusername /home/newusername/Downloads/oldusername-backup
share|improve this answer

Please try the below to change the user name in home directory,

usermod -d /home/newHomeDir -m newUsername

Hope this helps !

share|improve this answer
    
Tried the above but no luck .. Here's what I'm getting – Bala Jagannathan S Dec 10 '14 at 6:08
1  
After doing the above logout your machine and try login again. – vembutech Dec 10 '14 at 8:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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