Linux Change or Rename User Name and UID

How do I change user name (rename user name) or UID under a Linux operating system using command line tools? How do I change or rename username in Linux?

You need to use the usermod command to change user name under a Linux operating systems. This command modifies the system account files to reflect the changes that are specified on the command line. Do not edit /etc/passwd file by hand or using a text editor such as vi. This page explains how to change or rename username in Linux using the usermod command.

Linux Change or Rename User Command Syntax

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements None
Est. reading time 5m
The syntax is as follows to rename by user name:
usermod -l login-name old-name

  • We use the usermod command in Linux to rename user account. The name of the user will be changed from the old-name to login_name. Nothing else is changed. In particular, the user’s home directory name should probably be changed to reflect the new login name.

The syntax is as follows to rename by a UID (user ID):
usermod -u UID username

  • The numerical value of the user’s ID (UID) . This value must be unique unless the -o option is used. The value must be non-negative. Values between 0 and 99 are typically reserved for system accounts. Any files which the user owns and which are located in the directory tree rooted at the user’s home directory will have the file user ID changed automatically. Files outside of the user’s home directory must be altered

List all users in Linux system

Type the following cat command:
cat /etc/passwd
One can use the grep command to filter out only user names:
grep -w '^username' /etc/passwd
grep -w '^jerry' /etc/passwd

Another option is to use the cut command:
cut -d: -f1 /etc/passwd
Sample outputs:


How to Change or Rename Username and UID in Linux

Let us see how to rename user login. First, make sure user name is not logged into the server and any other process is not running under the same user name. I also recommend that you backup any data or server files before changing user names.

View current user and group membership for user named tom

First get user identity using the id command:
id tom
Next use the grep command to grab login info about user named tom from the /etc/passwd file
grep '^tom:' /etc/passwd
See group info about user named tom using the groups command:
grep 'tom' /etc/group
groups tom

Find home directory permissions for user named tom, run the following ls command:
ls -ld /home/tom/
Finally, see all Linux process owned by user and group named tom using the ps command:
ps aux | grep tom
ps -u tom

Fig.01: Getting info about user named 'tom' on a Linux based system

Fig.01: Getting info about user named ‘tom’ on a Linux based system

Rename and change username from tom to jerry on Linux

Type the usermod command as follows:
# id tom
# usermod -l jerry tom
## Verify ###
# id tom
# id jerry
# ls -ld /home/tom

A note about running process

You may see an error as follows if tom is logged in and running jobs:

# usermod -l jerry tom
usermod: user tom is currently used by process 6886

You need to kill all Linux process owned by user named tom and forcefully logged them out of the system:

# pkill -u tom pid
# pkill -9 -u tom
# usermod -l jerry tom

Rename and change primary groupname from tom to jerry

Type the usermod command as follows:
# id tom
# groupmod -n jerry tom
## Verify it ###
# id tom
# ls -ld /home/tom

Sample outputs:

Fig.02: Sample session renaming user on a Linux based server

Fig.02: Sample session renaming user on a Linux based server

How to change user home directory from /home/tom/ to /home/jerry

The syntax is as follows:
# usermod -d /home/jerry -m jerry
# id jerry
# ls -ld /home/jerry

Sample outputs:

uid=1001(jerry) gid=1001(jerry) groups=1001(jerry)
drwxr-xr-x 2 jerry jerry 4096 Apr 21 15:53 /home/jerry/

How to change user tom UID from 5001 to 10000

Type the usermod command as follows:
# id tom
# usermod -u 10000 tom
# id tom

Getting help about usermod command

You can pass the --help option to the usermod command. For instance, type the following command at the shell prompt in Linux:
usermod --help

Options Description
-c OR --comment COMMENT new value of the GECOS field
-d OR --home HOME_DIR new home directory for the user account
-e OR --expiredate EXPIRE_DATE set account expiration date to EXPIRE_DATE
-f OR --inactive INACTIVE set password inactive after expiration to INACTIVE
-g OR --gid GROUP force use GROUP as new primary group
-G OR --groups GROUPS new list of supplementary GROUPS
-a OR --append append the user to the supplemental GROUPS mentioned by the -G option without removing the user from other groups
-h OR --help display this help message and exit
-l OR --login NEW_LOGIN new value of the login name
-L OR --lock lock the user account
-m OR --move-home move contents of the home directory to the new location (use only with -d)
-o OR --non-unique allow using duplicate (non-unique) UID
-p OR --password PASSWORD use encrypted password for the new password
-R OR --root CHROOT_DIR directory to chroot into
-P OR --prefix PREFIX_DIR prefix directory where are located the /etc/* files
-s OR --shell SHELL new login shell for the user account
-u OR --uid UID new UID for the user account
-U OR --unlock unlock the user account
-v OR --add-subuids FIRST-LAST add range of subordinate uids
-V OR --del-subuids FIRST-LAST remove range of subordinate uids
-w OR --add-subgids FIRST-LAST add range of subordinate gids
-W OR --del-subgids FIRST-LAST remove range of subordinate gids
-Z OR --selinux-user SEUSER new SELinux user mapping for the user account


In this tutorial, you learned how to change or rename username and UID in Linux using the usermod command. Read man pages of usermod(8) and groupmod(8) commands for more information see this page.

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 64 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig 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 VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
64 comments… add one
  • Joe P. Nov 17, 2007 @ 21:10

    gave me exactly what I was looking for. Thanks.

    • balaji Mar 4, 2011 @ 14:17

      how to change the user name in linux

      • Nageswararao Dec 13, 2013 @ 13:03

        To change user name in linux just type the command (usermod -l Newname Oldname)

  • rxfelix Feb 12, 2008 @ 18:51

    You might want to mention the possible additional tasks required to make a complete username changeover, such as changing the home directory name, the mail spool file name, or the group names. Otherwise an unexperienced sysadmin might use this command but break the user’s mail or other services.

  • ubuntu Apr 22, 2008 @ 3:16

    killall -u old
    id old
    usermod -l new old
    groupmod -n new old
    usermod -d /home/new -m new
    usermod -c “New Real Name” new
    id new

    • Asif syed Mar 8, 2011 @ 16:51

      man usermod – we can view all details about user modifications and Changes.
      /etc/passwd – we can view all user ang group accounts, timestamps , bash.
      usermod -l new old – to change the user name
      usermod -d /home/new – to change the home directory
      usermod -c – to change the jickos..,field..

    • Skibbler May 6, 2013 @ 18:01

      Just what I needed. Thanks.

  • Sys Admin Jun 7, 2008 @ 11:00

    As with any potentially dangerous operation, you should back up the user’s data before the migration.

    This will allow you to recover from the situation should the problem arise.

  • johncruise Jun 8, 2008 @ 21:16

    very useful. thanks!

  • kamal Jan 6, 2009 @ 11:00

    open Suse
    chenge username

    usermod -l new old

  • hassan Mar 19, 2009 @ 5:10

    Can we creat a user with the root permissions? if yes please explain how?

    • kunal Oct 30, 2012 @ 11:07

      usermod -u 0 username

  • hassan Mar 19, 2009 @ 5:12

    Can we creat a user with the root permissions? if yes please explain how?
    I know root has 0 UID but when i try to assign 0 to any other user it gives me message that id is not unique.

  • Jo Jul 3, 2009 @ 0:31

    This tips is awesome!!!

  • Tamika crockrum Jul 5, 2009 @ 23:46

    Great ideal huh

  • dan Jul 10, 2009 @ 17:42

    How to give a user root privileges:
    1. open terminal and type “visudo” or “sudo visudo” (you need root privileges)
    2. find the line “root ALL=(ALL) ALL ”
    3. under that line copy the “root ALL…” line but replace root with your username
    example. “dan ALL=(ALL) ALL”
    4. make sure you don’t remove any lines in that file
    5. If you don’t want to use the visudo command, you could just use a text editor and edit the /etc/sudoers file.

    Hope that was helpful

    • JuR Jun 14, 2011 @ 20:29

      Thank you for that,
      but could you help me with saving the file? When I’m on terminal and have written all the needed modifications, how do I save and exit?


      • Aaron Jul 2, 2011 @ 15:58

        the editor you are using during that operation is vim

  • dan Jul 10, 2009 @ 17:48

    oh also, instead of adding a line in that file you could uncomment the line that starts with #%admin

    so it looks like %admin ALL=(ALL) ALL
    then save it
    add any users to the admin group to give them admin privileges

    same thing can be done for the”%sudo” line (although im not sure about it”

  • omar Jul 17, 2009 @ 14:37

    to change the login for ubuntu 9.04 I used:
    # sudo usermod -l

  • Ruben Sep 29, 2009 @ 21:33

    How do yo rename an account in unix sun Solaris 10

  • paula Ojukwu Oct 6, 2009 @ 21:37

    ok mine challenge is different.i want to change from root to a user name.
    i have tried all i know how.
    please some one help me.

  • lavanya Nov 25, 2009 @ 5:06

    change id

  • Jacques Nov 29, 2009 @ 12:29

    As I recall, usermod only updates UIDs for files in the user’s home directory and the mail spool. You also have to consider files in /tmp or /var that can be persistent between user sessions, or even reboots depending on your OS. I just do this to ensure that all files have been changed,

    find / -user 5001 -exec chown -h 10000 {} \;

    or maybe this,

    find / -user 5001 | xargs chown -h 10000

    Use the ‘-h’ switch to chown so that it updates the ownership of symbolic links rather than what the symlink points to.

    • mrom Aug 20, 2010 @ 10:12

      good hint! but i would rather use:

      # find / -user 5001 -print0 | xargs -0 chown -h 10000

      this handles files with spaces, backslashs or quotation marks correctly.

  • soundar Jan 28, 2010 @ 15:11

    to create user with non-unique UID
    useradd -g groupname -o -u UID newusername
    ie : useradd -g root -o -u 0 soundar

    • Anonymous May 7, 2010 @ 11:15

      Thank you! That works great!!

  • sayantan Feb 19, 2010 @ 5:48

    its leads to a gconf error on rhel 5.

  • kiran Mar 26, 2010 @ 11:32

    # useradd -g root -o -u 0 postgres
    UX: useradd: ERROR: Inconsistent password files. See pwconv(1M).

  • kiran Mar 26, 2010 @ 11:33

    # uname -a
    SunOS hyd-BNW 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-Fire-V240

  • Aldo "xoen" Giambelluca May 2, 2010 @ 7:44

    Maybe you saved my life :P, thank you :).

  • Dating in Ireland May 3, 2010 @ 18:04

    Exactly what I was looking for.

  • jseamus Jun 5, 2010 @ 21:17

    In Ubuntu 10.04, when I tried it, it returned this:

    $ sudo usermod -l new old
    usermod: user old is currently logged in

    This happened even when I was changing “old” to “new” from a different user account while “old” was logged out.

    Any help please?

    • Alex Oct 14, 2011 @ 14:24

      If you receive the error “usermod: user is currently logged in”, this is probably because you’re trying to change a username while their account is being used by one or more processes.

      Getting around this problem is usually pretty straightforward:

      – create a new user, e.g. I created an “admin” user, with root privileges
      – restart your machine and log in as them (this is the best way to ensure no processes continue to run as the user whose name you want to change)
      – retry the command (don’t forget you will probably need to run it with sudo, e.g. “sudo usermod -l “)

    • arr_sea Jul 24, 2013 @ 18:42

      One way around this is the following:
      First we become root, then we execute a command via nohup that will wait 30 seconds and then call the usermod command. Then log out of root and log out of your user account, and wait 1 minute. Then you should be able to log back in as your new user name.

      $ sudo su
      # nohup /bin/bash -c ‘sleep 30; usermod -l new_user_name -md /home/new_user_name old_user_name; touch ~/done.tmp’ &
      # exit
      $ exit
      and do whatever else you need to do to log out…

  • recluce Jun 14, 2010 @ 2:11

    It seems that you must restart your system in Ubuntu 10.04, login to the different user account and do the changes. Once you were logged in to the account to be changed, it will not work anymore. No idea why.

    BTW: if you use WINE, look at the .reg files of WINE and change your /home folder name accordingly – or you will seriously bork Wine!

  • pev Jan 4, 2011 @ 6:13

    Wow just what I was looking for thanks.

    Just remember to change the owner’s group (gid) as well (run this after the uid change)

    # find / -group 5001 -print0 | xargs -0 chown -h :10000

  • matias Feb 24, 2011 @ 10:01

    “$ sudo usermod -l new old
    usermod: user old is currently logged in”
    I killed all his tasks. It works.

  • Tim Mar 9, 2011 @ 9:25

    What’s the terminal file in unix ?
    Does the terminal files created when a use log in ?

  • suresh Aug 10, 2011 @ 13:41

    when iam changing username from root in linux with usermod -l [new username] [old username] it geting that user currently logged in

  • nt Sep 14, 2011 @ 18:43

    I want creat a user have id = 0. how can I do it??
    when I delete dir home of user I can’t login this user. Why?

  • naresh Nov 12, 2011 @ 6:11

    precise & useful

  • gnb Nov 16, 2011 @ 9:45

    will this work if my home drive (corresponding to the USR-NAME being changed) is encrypted? I am a bit afraid. Can you reply on this please! Thanks in advance — GNB

  • quick Dec 30, 2011 @ 22:51

    guys, I made a adjustment in sudoers file and deleted the % in the group section. afterwards i cannt access the sudoers file anymore.
    error my user do not have the permission to access.
    can someone help
    ubuntu 10.11

  • Raju May 1, 2012 @ 14:43

    I want to rename the username in particular file.
    example: demo.xml
    can some one help me

  • sharmila Sep 3, 2012 @ 10:13

    how to change the username..I don’t no old username….

  • Gopal Oct 21, 2012 @ 14:02

    A system has an existing user kkline for Kathy Kline but she just got married and is now Kathy Morgan. You need to change her username, home directory name, and real name on the system. What command(s) would you use?

    please provide the solution

  • Richard Oct 30, 2012 @ 19:29

    Amazing response. That guided me through perfectly with just what i needed. Best strait to the point response! Thank you!

  • Rafi Nov 1, 2012 @ 6:07

    When i change the user name then automaticaly change the group name also. I just only change the user name. How can i do that?

    • kunal Nov 1, 2012 @ 6:42

      After user created you can add group and execute below command

      # groupadd goupname
      # chown groupname:groupname DIRname -R

  • Dustin Brown Jun 21, 2013 @ 16:30

    Ok, I changed my username and now i can’t ssh into said user from another machine. Why? Ssh says permission denied. Here is id fgsim
    uid=1004(fgsim) gid=1004(fgsim) groups=1004(fgsim),1008(fgstudents)
    I edited both the passwd and group file.
    I use Fedora 16.

  • Mark Feb 21, 2014 @ 17:52

    Did you also edit /etc/shadow and /etc/gshadow?

  • Mark Feb 21, 2014 @ 17:54

    Also make sure your new username/group is in sshd_config for allowed groups.

  • jooe15 Mar 26, 2014 @ 19:30

    usermod not found? so i am using a zsh and i can’t find usermod, its not even in man — can’t find it in bash either. am i missing something?

  • sorefromubuntu Jun 19, 2014 @ 18:58

    I am not a novice, but clearly not learned enough to fix this damaging issue I just created, so thanks in advance for your help…

    1. I followed these instructions to a tee in order to change my old username into a new one:

    2. I also continued with specific home directory intsructions found here:…

    Now my username, group and home folder are all changed and permissions/ownership correct, as well as new user has been set to new home. I even ran the `cp -f /home/username/* /home/new_home_dir/` to copy over all home files to new folder. However, this didn’t work so well in my favor…


    I can login, I can access files in home, but ALL of my desktop, settings and home files are gone. Back to square 1, with only 1 clue in my new home folder: two files by the name of README and *Access-Your-Private-Data.desktop*.

    **Problem Key:**

    Old username: `OLD`

    New username: `NEW`

    New group: `NEWG1`

    My User ID Info:
    > uid=1000(NEW) gid=1000(NEWG1)
    > groups=1000(NEWG1),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),124(sambashare)

    UID `1000` has not changed even though the username changed.
    OLD was the user `1000`, as was `OLD` the home directory name.
    I changed the username to `NEW`, same UID (`1000`), and changed `OLD` group name to `NEWG1`.

    I did all of this from command line, by hitting `Ctrl+Alt+F1` from the login screen, then logging into a secondary account (not the `OLD` or the `NEW` account).


    Now, I can login all day long. However, my `OLD` account, which has been changed to `NEW`, looks like a brand new user account, and all of my data and files and configuration are gone when logged in using the `NEW` account. However, in the `/home/NEW` folder, I have these files:


    But no files such as:


    When trying to open Access-Your-Private-Data.desktop, terminal opens and closes instantly. So nothing happens. And when executing `ecryptfs-mount-private` I get the following;

    $ ecryptfs-mount-private
    ERROR: Encrypted private directory is not setup properly


    – How do I access the encrypted files and move, delete or alter them?
    – Where did all of my home files and config from `OLD` user go, if all
    – I did was change the username and group name, as well as home folder
    name (and even assign user to folder), and copy everything?
    – If it’s not encrypted, where did it all go?
    – Can I keep going and get it fixed with `NEW` everything?
    – Or, Can I backtrack properly to `OLD` everything?

    I looked in `/media/OLD`, but nothing is in there.

    I looked in `/tmp` but nothing like ‘*ecryptfs.123XYZ*’ is in there except *ssh-123XYZ* and *hsperfdata_NEW*.

    This guys made it look easy on what to do with the file:

    But again, this is not working for me.


    I am setting up a boot USB with Ubuntu 14, in hopes to follow directions on mounting properly (as in described here:, but I am not sure I am working correctly.

    Thanks in advance! This is amazingly important to recover my old setup, regardless of damn username and home folder name.

    Please help with this if you can.

    All the best!!!!

    PS – Here is a list of references that helped me screw up (I mean execute) the above:



  • Keshav Agrawal Aug 25, 2014 @ 3:42


  • wdm Feb 3, 2016 @ 13:32

    there is a lot of config files wich stores full path /home/olduser/…
    so you also have to go thru all and replace into /home/newuser/…

  • wdm Feb 3, 2016 @ 13:45

    or do that stuff with one command
    cd /home/newuser && find ./ -type f -readable -writable -exec sed -i “s/\/home\/olduser/\/home\/newuser/g” {} \;

  • Erick Mar 31, 2016 @ 21:07

    Very clear, as usual.Thank you Vivek

  • Darcy May 23, 2016 @ 1:52

    Perfect! Very helpful. I followed the steps to change username, group, and home folder. Worked like a charm. Thank you so much Vivek!

  • Rajeswary Jul 24, 2017 @ 9:12

    Mention killing of processes before mentioning usermod -l login-name user-name.

    It executed usermod -l, before killing processes. It was giving trouble.
    But thankfully, I reverted to previous username, killed processes and started afresh. That worked.

  • jully adan Sep 7, 2020 @ 8:37

    Nice. I like this blog.

  • Jayden Feb 13, 2021 @ 10:53

    If connected via SSH, create a new temporary user with sudo access to complete this process:

    sudo useradd tempuser
    sudo usermod -aG sudo tempuser
    sudo passwd tempuser

    Then login to tempuser with your password and complete the above process.

    Then sudo deluser tempuser to remove your temporary account.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum