Renaming user name [duplicate]

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


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.