How to change or modify the name of the user in Linux?

July 30, 2021 - 1 min read

To change the name of a user, you must use the usermod command followed by the -l flag (login name flag), the new name of the user, and finally the old name of the user.

# Syntax
sudo usermod -l new_user_name old_user_name

Imagine that we already have a user named john in the system and want to change the name to roy. To do that we can use the usermod command like this,

# Change or modify the name of the user in Linux
sudo usermod -l roy john
  • Sometimes you may need to use the sudo command before the usermod command to obtain the correct privileges to execute the command.

Try executing the above command in this online terminal to see the result.

That's all 😃!

Feel free to share if you found this useful 😃.