63

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 4

105

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
  • 2
    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. Oct 3, 2015 at 7:20
  • 3
    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 Oct 6, 2015 at 17:45
  • 2
    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. Nov 6, 2016 at 20:09
  • 2
    Instead of killall and usermod (which I didn't want to do through an SSH connection with the logged-in user) I had success with changing the user name in /etc/passwd and /etc/shadow .
    – krlmlr
    May 9, 2018 at 9:03
  • 1
    @BKSpurgeon Nope. After renaming the account, the new login is using the /home/oldname folder. You specify the new folder name and the user it's for, so newname both times. linux.die.net/man/8/usermod Jul 14, 2020 at 13:57
22

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
3

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
-3

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

usermod -d /home/newHomeDir -m newUsername

Hope this helps !

2
  • Tried the above but no luck .. Here's what I'm getting Dec 10, 2014 at 6:08
  • 1
    After doing the above logout your machine and try login again.
    – BDRSuite
    Dec 10, 2014 at 8:41

Not the answer you're looking for? Browse other questions tagged .