How to change username on Ubuntu using the command line

Usermod is your friend is you want to change the username and / or home directory of an Ubuntu user. The catch is you can’t change the username if you’re logged in as the user.

This is how you could do it:

sudo adduser temp
sudo adduser temp sudo

Logout as current user and log in as temp user. Now change the username:

sudo usermod -l newUsername oldUsername

Then change the home directory:

sudo usermod -d /home/newHomeDir -m newUsername

When you’re done, remove the temp user:

sudo deluser temporary
sudo rm -r /home/temporary

Reference:
https://askubuntu.com/questions/34074/how-do-i-change-my-username

Share this article

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top