Linux Change or rename UID and User Name

How do I modify person title (rename person title) or UID beneath a Linux working system utilizing command line instruments? How do I modify or rename username in Linux?

You want to use the usermod command to alter person title beneath a Linux working methods. This command modifies the system account recordsdata to mirror the modifications which can be specified on the command line. Don’t edit /and so forth/passwd file by hand or utilizing a textual content editor reminiscent of vi. This web page explains learn how to change or rename username in Linux utilizing the usermod command.


Linux Change or Rename Person Command Syntax

Tutorial particulars
Problem Straightforward (rss)
Root privileges Sure
Necessities None
Time 5m

The syntax is as follows to rename by person title:
usermod -l login-name old-name

  • We use the usermod command in Linux to rename person account. The title of the person will likely be modified from the old-name to login_name. Nothing else is modified. Specifically, the person’s house listing title ought to in all probability be modified to mirror the brand new login title.

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

  • The numerical worth of the person’s ID (UID) . This worth have to be distinctive except the -o choice is used. The worth have to be non-negative. Values between zero and 99 are usually reserved for system accounts. Any recordsdata which the person owns and that are situated within the listing tree rooted on the person’s house listing may have the file person ID modified robotically. Information exterior of the person’s house listing have to be altered

Kind the next cat command:
cat /and so forth/passwd
One can use the grep command to filter out solely person names:
grep -w ‘^username’ /and so forth/passwd
grep -w ‘^jerry’ /and so forth/passwd
Another choice is to make use of the lower command:
lower -d: -f1 /and so forth/passwd
Pattern outputs:

video games

Change or Rename Username and UID in Linux

Allow us to see learn how to rename person login. First, be certain that person title is just not logged into the server and every other course of is just not working beneath the identical person title. I additionally advocate that you simply backup any information or server recordsdata earlier than altering person names.

View present person and group membership for person named tom

First get person identification utilizing the id command:
id tom
Subsequent use the grep command to seize login information about person named tom from the /and so forth/passwd file
grep ‘^tom:’ /and so forth/passwd
See group information about person named tom utilizing the teams command:
grep ‘tom’ /and so forth/group
teams tom
Discover house listing permissions for person named tom, run the next ls command:
ls -ld /house/tom/
Lastly, see all Linux course of owned by person and group named tom utilizing the ps command:
ps aux | grep tom
ps -u tom

Linux Change or rename UID and User Name

Fig.01: Getting information about person named ‘tom’ on a Linux based mostly system

Rename and alter username from tom to jerry on Linux

Kind the usermod command as follows:
# id tom
# usermod -l jerry tom
## Confirm ###
# id tom
# id jerry
# ls -ld /house/tom

A notice about working course of

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

# usermod -l jerry tom
usermod: person tom is at the moment utilized by course of 6886

You want to kill all Linux course of owned by person named tom and forcefully logged them out of the system:

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

Rename and alter main groupname from tom to jerry

Kind the usermod command as follows:
# id tom
# groupmod -n jerry tom
## Confirm it ###
# id tom
# ls -ld /house/tom
Pattern outputs:

Linux Change or rename UID and User Name

Fig.02: Pattern session renaming person on a Linux based mostly server

change person house listing from /house/tom/ to /house/jerry

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

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

change person tom UID from 5001 to 10000

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

Getting assist about usermod command

You’ll be able to move the –help choice to the usermod command. For example, sort the next command on the shell immediate in Linux:
usermod –help

Choices Description
-c OR –comment COMMENT new worth of the GECOS area
-d OR –home HOME_DIR new house listing for the person 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 pressure use GROUP as new main group
-G OR –groups GROUPS new listing of supplementary GROUPS
-a OR –append append the person to the supplemental GROUPS talked about by the -G choice with out eradicating the person from different teams
-h OR –help show this assist message and exit
-l OR –login NEW_LOGIN new worth of the login title
-L OR –lock lock the person account
-m OR –move-home transfer contents of the house listing to the brand new location (use solely with -d)
-o OR –non-unique permit utilizing duplicate (non-unique) UID
-p OR –password PASSWORD use encrypted password for the brand new password
-R OR –root CHROOT_DIR listing to chroot into
-P OR –prefix PREFIX_DIR prefix listing the place are situated the /and so forth/* recordsdata
-s OR –shell SHELL new login shell for the person account
-u OR –uid UID new UID for the person account
-U OR –unlock unlock the person account
-v OR –add-subuids FIRST-LAST add vary of subordinate uids
-V OR –del-subuids FIRST-LAST take away vary of subordinate uids
-w OR –add-subgids FIRST-LAST add vary of subordinate gids
-W OR –del-subgids FIRST-LAST take away vary of subordinate gids
-Z OR –selinux-user SEUSER new SELinux person mapping for the person account


On this tutorial, you realized learn how to change or rename username and UID in Linux utilizing the usermod command. Learn man pages of usermod(8) and groupmod(8) instructions for extra info see this web page.

🐧 Get the most recent tutorials on SysAdmin, Linux/Unix, Open Supply/DevOps matters:


linux change user permissions,change file user linux,rename home directory linux,linux change group name,ubuntu 18.04 change username,usermod: user is currently used by process,ansible rename user,how to change the umask value in linux,unix usernames,rename user ubuntu,kali linux change user,user kali is currently used by process,kali linux how to change root name,how to change rootname,change name on terminal kali,how to change username in kali linux 2020,linux change user full name,linux remove user,linux change user name,linux change username and home directory,linux add user