In this post I'll show you how to rename you user account with example on Ubuntu Linux operating system. I did this the other day because I didn't like user name i gave to the Ubuntu installer, so i wanted to rename my account together with my home folder and all that goes with doing so...
First i have created temporary user account and joined it to the admin group. You can't mess with users account while being logged in to it (enabling root account on Ubuntu looked too messy). This is how to create user (remember the password you gave to adduser cause you'll need it to log in to your temp account):
sudo adduser temp sudo adduser temp admin |
Now we shall logout and log in as temp user but not using GUI way, instead we will use virtual terminal to do our magic. You should grab pen and paper (photographic memory should help also) to write down this procedure cause there is no GUI where we are headed.
Now restart your PC and when prompted for login press Ctrl+Alt+F1. On the virtual console tty1 log in with you temp user name and password you have provided to adduser command. Now enter these lines one by one replacing "oldname" and "newname" with what you have now and what you want to have after this is over.
sudo usermod -l newname -d /home/newname -m oldname sudo groupmod -n newname oldname sudo chown -R newname:newname /home/newname sudo deluser temp sudo reboot |
Some applications hardcode your home path in recent files and stuff like that (by the way that is very bad practice, people should use $HOME variable or something similar instead of hardcoding /home/username). Those hardcoded links wont work anymore because user name has changed. To track down those applications you could run something like following to find files in your home directory that contain old path string.
grep "home/oldname" -R .* |
Now update all files with your new home path and be on your way (Gedit : Search -> Replace). On my system only Virtualbox files had to be changed. That is it. Cheers!
Rating 5 stars, works perfect.
Hi, thank you for that useful and nice article.
Can you give me a hint how to acomplish a solution to the following situatio: I had a UBUNTU 8.04 and updated and updated until 11.04 and at the end i did a repairinstallation to 12.04 because it would not install 12.04 without errors.
But while doing the repairinstallation to 12.04 i gave a different username instead the old one. Now i have the /home/olduser and the /home/newuser files.
Is it possible to change the system in that way that it will treat my /home/olduser as the one and only user without deleting my files. I have backed them up so if somethings goes wrong it not a big problem.
At this stage i added a new user (olduser) and it took a while but ended with an error. After a reeboot the recently added new olduser was created.
What should i do net to make it happen?
Hello. When you create user it automatically uses directory from your /home with your user name if this directory has correct ownership. You just need to change owner for your /home/olduser directory to this newly created user (olduser you call it) like this “sudo chown -R olduser /home/olduser” and log in with “olduser” name. After you login you can delete new user account using GUI tools and it will ask you do you wan’t to delete /home/newuser. Good luck!
Hi Marko, at this moment my recenty added “OLDUSER” is deactivated. Should i activate it first before changing the rights? How do i change the rights exactly…. ??
Start a live system and do it with a console or just login as the “wrongnewuser” and do it with your command i a console??? thx & greets
I do this very often, usually after distro hopping or similar and I do it this way: Just log out of your desktop environment and when on login screen press Ctrl+Alt+F2 to go to virtual terminal. There you login with wrong user, and:
Then you type
exit
to log out of wrong user and log in as “olduser”. If everything went right you’ll find your self on your old desktop with your good old /home/olduser home. Then just use GUI tools or command line to delete that wrong user including that /home/wronguser directory and be on your way. Once you removed that wrong user if you can manually remove its home directory like this (this is irreversible!):The -f means force and -R means recursion into directories of /home/wronguser when removing. By the way any command has its man (user manual) page accessible with “man command” for more info. You exit man pages by pressing
q
on your keyboard.Hi Marko, great post!
This command is great for updating all files which contains old users home directory:
find /home/newuser -type f -readable -writable -exec sed -i "s|home/olduser|home/newuser|g" {} \;
Easiest solution 🙂