How to change a user’s username on Linux?

I want to rename a user’s username on Linux. For example, rename user u1 to user1. How to change a user’s username on Linux?

You can use the usermod command to modify the user’s info.

For changing the user name, you can use the -l option:

-l, –login NEW_LOGIN

The name of the user will be changed from LOGIN to NEW_LOGIN. Nothing else is changed. In particular, the user’s home directory or mail spool should probably be renamed manually to reflect the new login name.

For your specific example, the command will be (run as root or by sudo)

usermod -l user1 u1
Answered by Eric Z Ma.

Eric Z Ma

Eric is a father and systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

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