Renaming user name [duplicate]
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 .. ?
14 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 balajaWhenever you want to get back from console version to graphical version:
Press Ctrl+Alt+F7
10on the server this worked for me:
sudo usermod -md /home/NewHome -l NewName OldName
sudo groupmod -n NewGroupName OldGroupNameThis renames the user and its group and also the home folder.
0This 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
killmenowwith pass of same, make him admin, reboot and log in askillmenow. - open terminal, riun
sudo i, thenmkdir /home/newusernameand making it the same uid:gid as theoldusername - 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/passwdand/etc/groupto referencenewusernameand/home/newusernamepasswd newusernameand enter a temporary password twice reboot and log in asnewusername, password being what you entered in the previous point.- delete
killmenowusing "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 newUsernameHope this helps !
2