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 .. ?

1

4 Answers

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 "[full name (new)]" [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

10

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.

0

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 

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

usermod -d /home/newHomeDir -m newUsername 

Hope this helps !

2