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.
Featured Articles:
- 20 Linux System Monitoring Tools Every SysAdmin Should Know
- 20 Linux Server Hardening Security Tips
- My 10 UNIX Command Line Mistakes
- Linux: 20 Iptables Examples For New SysAdmins

- 25 PHP Security Best Practices For Sys Admins
- The Novice Guide To Buying A Linux Laptop
- 10 Greatest Open Source Software Of 2009
- Top 5 Email Client For Linux, Mac OS X, and Windows Users
- Top 20 OpenSSH Server Best Security Practices
- Top 10 Open Source Web-Based Project Management Software
- Top 5 Linux Video Editor Software
Facebook it - Tweet it - Print it -


{ 37 comments… read them below or add one }
gave me exactly what I was looking for. Thanks.
how to change the user name in linux
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.
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
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.
very useful. thanks!
open Suse
chenge username
usermod -l new old
Can we creat a user with the root permissions? if yes please explain how?
Can we creat a user with the root permissions? if yes please explain how?
I know root has 0 UID but when i try to assign 0 to any other user it gives me message that id is not unique.
This tips is awesome!!!
Thanks
Great ideal huh
How to give a user root privileges:
1. open terminal and type “visudo” or “sudo visudo” (you need root privileges)
2. find the line “root ALL=(ALL) ALL ”
3. under that line copy the “root ALL…” line but replace root with your username
example. “dan ALL=(ALL) ALL”
4. make sure you don’t remove any lines in that file
5. If you don’t want to use the visudo command, you could just use a text editor and edit the /etc/sudoers file.
Hope that was helpful
-dan
Thank you for that,
but could you help me with saving the file? When I’m on terminal and have written all the needed modifications, how do I save and exit?
Cheers
the editor you are using during that operation is vim
oh also, instead of adding a line in that file you could uncomment the line that starts with #%admin
so it looks like %admin ALL=(ALL) ALL
then save it
add any users to the admin group to give them admin privileges
same thing can be done for the”%sudo” line (although im not sure about it”
to change the login for ubuntu 9.04 I used:
# sudo usermod -l
How do yo rename an account in unix sun Solaris 10
ok mine challenge is different.i want to change from root to a user name.
i have tried all i know how.
please some one help me.
change id
As I recall, usermod only updates UIDs for files in the user’s home directory and the mail spool. You also have to consider files in /tmp or /var that can be persistent between user sessions, or even reboots depending on your OS. I just do this to ensure that all files have been changed,
find / -user 5001 -exec chown -h 10000 {} \;or maybe this,
find / -user 5001 | xargs chown -h 10000Use the ‘-h’ switch to chown so that it updates the ownership of symbolic links rather than what the symlink points to.
good hint! but i would rather use:
# find / -user 5001 -print0 | xargs -0 chown -h 10000
this handles files with spaces, backslashs or quotation marks correctly.
hi
to create user with non-unique UID
useradd -g groupname -o -u UID newusername
ie : useradd -g root -o -u 0 soundar
Thank you! That works great!!
its leads to a gconf error on rhel 5.
# useradd -g root -o -u 0 postgres
UX: useradd: ERROR: Inconsistent password files. See pwconv(1M).
# uname -a
SunOS hyd-BNW 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-Fire-V240
Maybe you saved my life :P, thank you :).
Exactly what I was looking for.
Thanks!
In Ubuntu 10.04, when I tried it, it returned this:
$ sudo usermod -l new oldusermod: user old is currently logged in
This happened even when I was changing “old” to “new” from a different user account while “old” was logged out.
Any help please?
If you receive the error “usermod: user is currently logged in”, this is probably because you’re trying to change a username while their account is being used by one or more processes.
Getting around this problem is usually pretty straightforward:
- create a new user, e.g. I created an “admin” user, with root privileges
- restart your machine and log in as them (this is the best way to ensure no processes continue to run as the user whose name you want to change)
- retry the command (don’t forget you will probably need to run it with sudo, e.g. “sudo usermod -l “)
It seems that you must restart your system in Ubuntu 10.04, login to the different user account and do the changes. Once you were logged in to the account to be changed, it will not work anymore. No idea why.
BTW: if you use WINE, look at the .reg files of WINE and change your /home folder name accordingly – or you will seriously bork Wine!
Wow just what I was looking for thanks.
Just remember to change the owner’s group (gid) as well (run this after the uid change)
# find / -group 5001 -print0 | xargs -0 chown -h :10000
“$ sudo usermod -l new old
usermod: user old is currently logged in”
I killed all his tasks. It works.
What’s the terminal file in unix ?
Does the terminal files created when a use log in ?
I want creat a user have id = 0. how can I do it??
when I delete dir home of user I can’t login this user. Why?
will this work if my home drive (corresponding to the USR-NAME being changed) is encrypted? I am a bit afraid. Can you reply on this please! Thanks in advance — GNB
guys, I made a adjustment in sudoers file and deleted the % in the group section. afterwards i cannt access the sudoers file anymore.
error my user do not have the permission to access.
can someone help
ubuntu 10.11