How to change user name in Linux

Sometime you may want to change the user login name into different one,
In that case you can use two options

(Login or switch to root mode – su)

Method 1: ( Using usermod command )
usermod -l newname oldname

Example
#usermod -l anthoniraj antony

Here the user antony has been changed to anthoniraj

Method 2 : ( Using chfn command )
chfn -f newname oldname

Example
#chfn -f thiraviam thiravi

Here the user thiravi has been changed to thiraviam

Note : The old user name should exists in /etc/passwd file .
These above two commands will only change the user name, not user home directory.

Leave a Response