Linux change or rename user name and UID (user-id)
Q. How do I change user name (rename user name) or UID under Linux operating system?
A. Use the usermod command to change user name under Linux. it modifies the system account files to reflect the changes that are specified on the command line.
Syntax is as follows
usermod -l login-name old-name
Where,
=> The name of the user will be changed from old-name to login_name. Nothing else is changed. In particular, the user's home directory name should probably be changed to
reflect the new login name.
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 at 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.
Task: Change username from tom to jerry
Type usermod command as follows:
# id tom
# usermod -l jerry tom
# id jerry
# id tom
Task: Change user tom UID from 5001 to 10000
Type usermod command as follows
# id tom
# usermod -u 10000 tom
# id tom
Read man page of usermod for more information.
Subscribe to our free e-mail newsletter or RSS feed to get all updates.
You can Email this page to a friend.
Related Other Helpful FAQs:
- Howto: Changing Linux Login Shell
- Linux set or change user password how to
- renice command: Change the Priority of a Already Running Process
- Linux change the runlevel for a server without rebooting
- Linux or UNIX change file permissions recursively ( conditional )
Discussion on This FAQ
Leave a Reply
We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!
Tags: account_files, directory_name, directory_tree, id_command, system_accounts, usermod_command



November 17th, 2007 at 9:10 pm
gave me exactly what I was looking for. Thanks.
February 12th, 2008 at 6:51 pm
You might want to mention the possible additional tasks required to make a complete username changeover, such as changing the home directory name, the mail spool file name, or the group names. Otherwise an unexperienced sysadmin might use this command but break the user’s mail or other services.
April 22nd, 2008 at 3:16 am
killall -u old
id old
usermod -l new old
groupmod -n new old
usermod -d /home/new -m new
usermod -c “New Real Name” new
id new
June 7th, 2008 at 11:00 am
As with any potentially dangerous operation, you should back up the user’s data before the migration.
This will allow you to recover from the situation should the problem arise.
June 8th, 2008 at 9:16 pm
very useful. thanks!