Ubuntu: Rename an Account [ User ID ]

last updated in Categories

How do I rename a user name from ‘tom’ to ‘jerry’ under Ubuntu Linux?

You need to use the usermod command. It can modify the system account files (such as /etc/passwd) to reflect the changes that are specified on the command line. The syntax is as follows:
usermod -l {new-login-name} {current-old-login-name}
In this example, rename login id from tom to jerry. Open a command-line terminal (select Applications > Accessories > Terminal), and then type the following command
$ sudo usermod -l jerry tom
To verify new changes, enter:
$ id jerry

Advertisements

ADVERTISEMENTS

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

3 comment

  1. Correct me if I am wrong though, but this does not change the user’s home directory to match the new ID, right?

    1. Try the -m and -d /home/jerry option; the contents of the current home directory will be moved to the new home directory, which is created if it does not already exist:

      usermod -m -d /home/jerry -l jerry tom
      ### gone ###
      ls /home/tom 
      ### as it moved to ###
      ls /home/jerry
      

      You may have to take care of secondary group memberhsip too.

    Still, have a question? Get help on our forum!