Home » Linux » Ubuntu » Ubuntu – How do I change my username?

About Ahmad Gohar

Ahmad Gohar
Technical Team Leader with 9+ years experience in designing and developing enterprise Solution using Oracle, IBM, and Open Source. With a solid technical and academic background. Strong technical project management experience, coordinate demo's for QA team, performing code, design and test plan reviews.

Ubuntu – How do I change my username?

Unix-like
operating systems decouple the user name from the user identity, so you may safely change the name without affecting the ID. All permissions, files, etc are tied to your identity (uid), not your username.

To manage every aspect of the user database, you use the usermod tool.

1- To change username (it is probably best to do this without being logged in):

sudo usermod -l newUsername oldUsername

This however, doesn’t rename the home folder.

2- To change home-folder, use

sudo usermod -d /home/newHomeDir -m newUsername

after you changed the username.

For instance, you could logout, drop to a console (Ctrl+Alt+F1), and sudo su - to become true root (as opposed to sudo -s, where $HOME is still /home/yourname.) Maybe you also have to kill some still running processes from this user first. To do so, enter ps -u username, look for the matching PID and kill them by kill PID-number.

Update: as arrange mentioned, some files may reference your old home directory. You can either keep a symlink for backward compatibility, e g ln -s /home/newname /home/oldname or you can change the file contents with sed -i.bak 's/*oldname*/*newname*/g' *list of files* It creates a backup for each file with a .bak extension.

Some additional information for not so experienced users like me:
As I only have ONE user account (administrator), it would not let me change the username ("you are already logged in" was the response in TTY1 (Ctrl+Alt+F1). To get around this:

  1. Login with your old credentials and add a new user, e.g. "temporary" in TTY1:
    sudo adduser temporary

    set the password.

  2. Allow the temporary user to run sudo by adding the user to sudo group:
    sudo adduser temporary sudo
  3. Log out with the command exit.
  4. Return to tty1: Login with the ‘temporary’ user account and password. Change your username and folder as mentioned above. exit (until you get the login prompt)
  5. Go back to TTY7 (Ctrl+Alt+F7) to login on the GUI/normal desktop screen and see if this works.
  6. Delete temporary user and folder:
    sudo deluser temporary
    sudo rm -r /home/temporary

NB: Copied from several resources. Thanks for the contribution.

Published on System Code Geeks with permission by Ahmad Gohar, partner at our SCG program. See the original article here: Ubuntu – How do I change my username?

Opinions expressed by System Code Geeks contributors are their own.

(0 rating, 0 votes)
You need to be a registered member to rate this.
Start the discussion Views Tweet it!
Do you want to know how to develop your skillset to become a Sysadmin Rockstar?
Subscribe to our newsletter to start Rocking right now!
To get you started we give you our best selling eBooks for FREE!
1. Introduction to NGINX
2. Apache HTTP Server Cookbook
3. VirtualBox Essentials
4. Nagios Monitoring Cookbook
5. Linux BASH Programming Cookbook
6. Postgresql Database Tutorial
and many more ....
Email address:

Leave a Reply

Be the First to Comment!

avatar
  Subscribe  
Notify of