Linux rename user command

I’ve gotten this question a whole bunch of times in the past.  You’ve got a Linux username that you want to rename, rather than recreate, so you don’t lose any significate data or permission settings.  How do you rename a Linux user?

Linux rename user command

To rename a Linux user (rename user name), you want to use the Linux command usermod.  From the man page:

The usermod command modifies the system account files to reflect the changes that are specified on the command line.

In short, here is the command to rename the Linux user:

usermod -d "/home/current_user-name" -m -l current_user_name new_user-name

And now an explanation of what each option means:

  • -d specifies the current users home directory.
  • -m specifies that you want to move the files from the current users home directory, to the new directory. You want to make sure you specify this, otherwise the users data will not transfer over to the new user account.
  • -l specifies the current user name, and the new user name you wish to change it to.

That’s it. Now you’ve renamed a Linux user.

3 thoughts on “Linux rename user command

  1. Tried your solutions numerous time … Never worked for me using Ubuntu-1010

    Tried it as user Root and another Privileged user so I wasn’t logged in to the account I was trying to rename and move.

    Got Directory not found when the command tried to create the new_user directory. I created the new directory and still no transfer of files from current_user directory.

    May have read it wrong but while looking for additional solutions that would work… other sites instruct the -l current_user and new_user command to be swapped from your instructions when renaming the user. Using the usermod -l command I can get it to rename back and forth but using your instructions I could not get it to move any directory content

    Was there additional instructions that I missed somewhere?

    Not a crisis here as I finally gave up and did a new install but I would like to learn what I did wrong.

  2. I’m pretty sure that

    > usermod -d “/home/current_user-name”

    should be:

    usermod -d “/home/new_user-name”

Leave a Reply

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

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>