How to rename user in Linux (also rename group & home directory)

We might have come across a situation where we might want to rename user in Linux system, for whatever reasons. We can easily rename user in Linux & also we can rename the home directory or its UID as well.

In this short tutorial, we will be discussing these things only. Let’s start by renaming user in Linux first,

(Recommended Read: How to use FIND command to locate anything in Linux)


Rename user in Linux

For renaming user in Linux systems, we will use ‘usermod’ command. Syntax for the command is,

$ usermod -l new_username old_username

For example, if we have a user named ‘dan’ & want to rename it to ‘susan’, execute the following command from terminal;

$ sudo usermod -l susan dan

This will only change the username & everything else, like group, home directory, UID will remain same.

Note:- You should need to logged out from the account you are trying to rename. You can also kill all the processes running for that user, to do so execute the following command,

$ sudo pkill -u dan

$ sudo pkill -9 -u dan


Renaming Home directory

For renaming home directory to correspond to the renamed user, we use ‘-d’ option with ‘usermod’ command.,

$ sudo usermod -d /home/susan -m susan


Changing UID for the user

To change the UID of the user , execute the following command,

$ sudo usermod -u 2000 susan

where ‘2000’ is the new UID for user.


Renaming the group

To rename the group from ‘dan’ to ‘susan‘, we will use ‘groupmod’ command. Use the following command to rename the group,

$ groupmod -n susan dan

To use a name that’s already in use but you want to use it anyway, command would be,

$ groupmod -o -n susan dan

Once we have made the required changes, we can than check the changes made using the ‘id’ command,

$ id susan

With this we end this tutorial on how to rename user in Linux. Please let us know if you have any question or any issue or if you do have any suggestion, please do let us know that as well.

If you think we have helped you or just want to support us, please consider these :-

Connect to us: Facebook | Twitter | Google Plus

Donate us some of you hard earned money:

Linux TechLab is thankful for your continued support.


Passionate about Linux & open source. Loves to learn, read & write about Linux as well as new technologies.

You may also like...

7 Responses

  1. way wed says:

    Did not quite work. Most did however the groupmod command follwoing your precise instructions resulted in an error.

    groupmod: group ‘susan’ already exists
    [root@think ~]# id susan
    uid=1000(susan) gid=1000(dan) groups=1000(dan),10(wheel)

  2. TomW says:

    You may want to modify any files created by dan and have them now owned by susan (you’ll need the original UID for dan, we’ll assume 1990 in this example)

    find / -uid 1990 -exec chown -h 2000 {} +

    The group seems to have been renamed so the group id didn’t change… but if it had, you’d similarly need to change the group id for dan grouped files (the example below assumes dan’s old group id is 1005 and susan’s new group id is 1006)

    find / -gid 1005 -exec chgrp -h 1006 {} +

Leave a Reply

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