Ubuntu: Rename an Account [ User ID ]

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

🐧 Get the latest tutorials on SysAdmin, Linux/Unix, Open Source/DevOps topics:
CategoryList of Unix and Linux commands
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network Utilitiesdig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNCentOS 8 Debian 10 Firewall Ubuntu 20.04

ADVERTISEMENTS
3 comments… add one
  • Kirk Dec 15, 2010 @ 17:21

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

    • 🐧 nixCraft Dec 15, 2010 @ 18:38

      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.

      • Kirk Dec 15, 2010 @ 20:37

        Exactly. Be worth updating your original FAQ, no so that the user transformation is complete.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre>, <code>...</code> and <kbd>...</kbd> for code samples.