Usermod is a useful command to manage user settings. It modifies the system account files to reflect the changes that are specified on the command line. It is capable of doing a lot of things, but here we will see how to change username and UserID or uid on Linux using usermod.
Change the username using Usermod
The command syntax is simple:
[root]# usermod -l new_username old_username
The above command only changes the username, nothing else is done. So, its a good practice to manually change the user home directory to reflect the change.
[root]# mv /home/old_username /home/new_username
Change the UID/UserID using Usermod
Here’s the syntax.
[root]# usermod -u UID username
Please note that, UID 0-999 are reserved for system accounts and should not be used. The above command will change the ownership of all the content owned by the user in his home directory; stuff outside the home directory needs to be manually fixed.
For more information, take a look at usermod’s manpage.