> ## Content Index
> Fetch the complete content index at: https://snubmonkey.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Rename or Change User Name and UID on Linux Systems.
- URL: https://snubmonkey.com/rename-or-change-user-name-and-uid-in-linux-system/
- Published: 2021-03-24T11:47:00.000Z
- Updated: 2025-04-16T22:56:09.000Z
- Description: You might have come across a situation where you want to rename a user name in Linux system, for whatever reasons. In this short tutorial, we will be discussing how to change user name (rename user name) or UID under a Linux operating system using command line tools.
- Author: yannick Coffi
- Tags: how to 🪄, linux 🐧

We will see and use the `usermod` command to change a username in Unix/Linux distributions. `usermod`is used to modify or change any attributes of an already created user account via command line. It is similar to the `useradd` or `adduser`command only here the login is granted to an existing user.  
  
*PS*: do not edit `/etc/passwd` file by hand or by using a text editor such as `nano` or `vi`.

## Rename/ change by user name 

  
**First**: You need to log out of the account you are trying to rename. Either by simply logging out or by killing all the processes running for that user. Execute the following command:

```zsh
$ sudo pkill -u USER
or 
sudo pkill -9 -u USER
```

Now, back to our previous example.  
The syntax is as follows:

```zsh
$ usermod -l new_username old_username
```

ie. If you have a user named **'batman'** and want to rename it to **'snubmonkey'**, execute the following command from your terminal.

```zsh
$ usermod -l batman snubmonkey
```

Remember, this will only change the username; everything else, like group, home directory, and UID, will remain the same.

##   
Change user UID (user ID)  

The syntax is as follows:

```zsh
$ usermod -u UID username
```

where, 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, in the user’s home directory will have the file user ID changed automatically. Files outside of the user’s home directory must be altered  
manually.

In the example below, you see that the user account **snubmonkey** holds the UID of **1003**, now we want to change it to **777** as a new UID. 

```zsh
$ id snubmonkey
uid=1003(snubmonkey) gid=1003(snubmonkey) groups=1003(snubmonkey),4(adm),24(cdrom),
27(sudo),30(dip),46(plugdev),116(lxd),1004(XX),
1005(PIC),1006(RNC),1008(Q),123(lpadmin)
```

Now, let’s change the UID for user **snubmonkey** using **`-u`** (uid) option and verify the changes.

```zsh
$ usermod -u 777 snubmonkey
uid=777(snubmonkey) gid=1003(snubmonkey) groups=1003(snubmonkey),4(adm),24(cdrom),27(sudo),
30(dip),46(plugdev),116(lxd),1004(XX),1005(PIC),
1006(RNC),1008(Q),123(lpadmin)
```

##   
Rename and change the primary groupname

To rename the group from **'king'** to **'queen'**, we will use the **`groupmod`** command.   
Use the following command to rename the group:

```zsh
$ ugroupmod -n king queen
```

To use a name that already exists, just apply the following command:

```zsh
$ ugroupmod -o -n king queen
```
  
  
...with this, we end this tutorial on how to rename users in Linux.