{ 56 comments… read them below or add one }

1 Joe P. November 17, 2007 at 9:10 pm

gave me exactly what I was looking for. Thanks.

Reply

2 balaji March 4, 2011 at 2:17 pm

how to change the user name in linux

Reply

3 Nageswararao December 13, 2013 at 1:03 pm

To change user name in linux just type the command (usermod -l Newname Oldname)

Reply

4 rxfelix February 12, 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.

Reply

5 ubuntu April 22, 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

Reply

6 Asif syed March 8, 2011 at 4:51 pm

man usermod – we can view all details about user modifications and Changes.
/etc/passwd – we can view all user ang group accounts, timestamps , bash.
usermod -l new old – to change the user name
usermod -d /home/new – to change the home directory
usermod -c – to change the jickos..,field..

Reply

7 Skibbler May 6, 2013 at 6:01 pm

Just what I needed. Thanks.

Reply

8 Sys Admin June 7, 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.

Reply

9 johncruise June 8, 2008 at 9:16 pm

very useful. thanks!

Reply

10 kamal January 6, 2009 at 11:00 am

open Suse
chenge username

usermod -l new old

Reply

11 hassan March 19, 2009 at 5:10 am

Can we creat a user with the root permissions? if yes please explain how?

Reply

12 kunal October 30, 2012 at 11:07 am

usermod -u 0 username

Reply

13 hassan March 19, 2009 at 5:12 am

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.

Reply

14 Jo July 3, 2009 at 12:31 am

This tips is awesome!!!
Thanks

Reply

15 Tamika crockrum July 5, 2009 at 11:46 pm

Great ideal huh

Reply

16 dan July 10, 2009 at 5:42 pm

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

Reply

17 JuR June 14, 2011 at 8:29 pm

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

Reply

18 Aaron July 2, 2011 at 3:58 pm

the editor you are using during that operation is vim

Reply

19 dan July 10, 2009 at 5:48 pm

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”

Reply

20 omar July 17, 2009 at 2:37 pm

to change the login for ubuntu 9.04 I used:
# sudo usermod -l

Reply

21 Ruben September 29, 2009 at 9:33 pm

How do yo rename an account in unix sun Solaris 10

Reply

22 paula Ojukwu October 6, 2009 at 9:37 pm

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.

Reply

23 lavanya November 25, 2009 at 5:06 am

change id

Reply

24 Jacques November 29, 2009 at 12:29 pm

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 10000

Use the ‘-h’ switch to chown so that it updates the ownership of symbolic links rather than what the symlink points to.

Reply

25 mrom August 20, 2010 at 10:12 am

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.

Reply

26 soundar January 28, 2010 at 3:11 pm

hi
to create user with non-unique UID
useradd -g groupname -o -u UID newusername
ie : useradd -g root -o -u 0 soundar

Reply

27 Anonymous May 7, 2010 at 11:15 am

Thank you! That works great!!

Reply

28 sayantan February 19, 2010 at 5:48 am

its leads to a gconf error on rhel 5.

Reply

29 kiran March 26, 2010 at 11:32 am

# useradd -g root -o -u 0 postgres
UX: useradd: ERROR: Inconsistent password files. See pwconv(1M).

Reply

30 kiran March 26, 2010 at 11:33 am

# uname -a
SunOS hyd-BNW 5.10 Generic_139555-08 sun4u sparc SUNW,Sun-Fire-V240

Reply

31 Aldo "xoen" Giambelluca May 2, 2010 at 7:44 am

Maybe you saved my life :P, thank you :).

Reply

32 Dating in Ireland May 3, 2010 at 6:04 pm

Exactly what I was looking for.
Thanks!

Reply

33 jseamus June 5, 2010 at 9:17 pm

In Ubuntu 10.04, when I tried it, it returned this:

$ sudo usermod -l new old
usermod: 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?

Reply

34 Alex October 14, 2011 at 2:24 pm

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 “)

Reply

35 arr_sea July 24, 2013 at 6:42 pm

One way around this is the following:
First we become root, then we execute a command via nohup that will wait 30 seconds and then call the usermod command. Then log out of root and log out of your user account, and wait 1 minute. Then you should be able to log back in as your new user name.

$ sudo su
# nohup /bin/bash -c ‘sleep 30; usermod -l new_user_name -md /home/new_user_name old_user_name; touch ~/done.tmp’ &
# exit
$ exit
and do whatever else you need to do to log out…

Reply

36 recluce June 14, 2010 at 2:11 am

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!

Reply

37 pev January 4, 2011 at 6:13 am

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

Reply

38 matias February 24, 2011 at 10:01 am

“$ sudo usermod -l new old
usermod: user old is currently logged in”
I killed all his tasks. It works.

Reply

39 Tim March 9, 2011 at 9:25 am

What’s the terminal file in unix ?
Does the terminal files created when a use log in ?

Reply

40 suresh August 10, 2011 at 1:41 pm

when iam changing username from root in linux with usermod -l [new username] [old username] it geting that user currently logged in

Reply

41 nt September 14, 2011 at 6:43 pm

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?

Reply

42 naresh November 12, 2011 at 6:11 am

precise & useful

Reply

43 gnb November 16, 2011 at 9:45 am

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

Reply

44 quick December 30, 2011 at 10:51 pm

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

Reply

45 Raju May 1, 2012 at 2:43 pm

I want to rename the username in particular file.
example: demo.xml
can some one help me

Reply

46 sharmila September 3, 2012 at 10:13 am

how to change the username..I don’t no old username….

Reply

47 Gopal October 21, 2012 at 2:02 pm

A system has an existing user kkline for Kathy Kline but she just got married and is now Kathy Morgan. You need to change her username, home directory name, and real name on the system. What command(s) would you use?

please provide the solution

Reply

48 Richard October 30, 2012 at 7:29 pm

Amazing response. That guided me through perfectly with just what i needed. Best strait to the point response! Thank you!

Reply

49 Rafi November 1, 2012 at 6:07 am

When i change the user name then automaticaly change the group name also. I just only change the user name. How can i do that?

Reply

50 kunal November 1, 2012 at 6:42 am

After user created you can add group and execute below command

# groupadd goupname
# chown groupname:groupname DIRname -R

Reply

51 Dustin Brown June 21, 2013 at 4:30 pm

Ok, I changed my username and now i can’t ssh into said user from another machine. Why? Ssh says permission denied. Here is id fgsim
uid=1004(fgsim) gid=1004(fgsim) groups=1004(fgsim),1008(fgstudents)
I edited both the passwd and group file.
I use Fedora 16.

Reply

52 Mark February 21, 2014 at 5:52 pm

Did you also edit /etc/shadow and /etc/gshadow?

Reply

53 Mark February 21, 2014 at 5:54 pm

Also make sure your new username/group is in sshd_config for allowed groups.

Reply

54 jooe15 March 26, 2014 at 7:30 pm

usermod not found? so i am using a zsh and i can’t find usermod, its not even in man — can’t find it in bash either. am i missing something?

Reply

55 sorefromubuntu June 19, 2014 at 6:58 pm

I am not a novice, but clearly not learned enough to fix this damaging issue I just created, so thanks in advance for your help…

1. I followed these instructions to a tee in order to change my old username into a new one: http://www.cyberciti.biz/faq/howto-change-rename-user-name-id

2. I also continued with specific home directory intsructions found here: http://jesin.tk/change-home-directory-in-linux/)…

Now my username, group and home folder are all changed and permissions/ownership correct, as well as new user has been set to new home. I even ran the `cp -f /home/username/* /home/new_home_dir/` to copy over all home files to new folder. However, this didn’t work so well in my favor…

PROBLEM
——-

I can login, I can access files in home, but ALL of my desktop, settings and home files are gone. Back to square 1, with only 1 clue in my new home folder: two files by the name of README and *Access-Your-Private-Data.desktop*.

**Problem Key:**

Old username: `OLD`

New username: `NEW`

New group: `NEWG1`

My User ID Info:
> uid=1000(NEW) gid=1000(NEWG1)
> groups=1000(NEWG1),4(adm),24(cdrom),27(sudo),30(dip),46(plugdev),107(lpadmin),124(sambashare)

UID `1000` has not changed even though the username changed.
OLD was the user `1000`, as was `OLD` the home directory name.
I changed the username to `NEW`, same UID (`1000`), and changed `OLD` group name to `NEWG1`.

I did all of this from command line, by hitting `Ctrl+Alt+F1` from the login screen, then logging into a secondary account (not the `OLD` or the `NEW` account).

MAIN ISSUE IN NEED HELP WITH:
—————————–

Now, I can login all day long. However, my `OLD` account, which has been changed to `NEW`, looks like a brand new user account, and all of my data and files and configuration are gone when logged in using the `NEW` account. However, in the `/home/NEW` folder, I have these files:

Access-Your-Private-Data.desktop
README.txt

But no files such as:

.ecryptfs
.private
…etc

When trying to open Access-Your-Private-Data.desktop, terminal opens and closes instantly. So nothing happens. And when executing `ecryptfs-mount-private` I get the following;

$ ecryptfs-mount-private
ERROR: Encrypted private directory is not setup properly

QUESTIONS:
———-

– How do I access the encrypted files and move, delete or alter them?
– Where did all of my home files and config from `OLD` user go, if all
– I did was change the username and group name, as well as home folder
name (and even assign user to folder), and copy everything?
– If it’s not encrypted, where did it all go?
– Can I keep going and get it fixed with `NEW` everything?
– Or, Can I backtrack properly to `OLD` everything?

I looked in `/media/OLD`, but nothing is in there.

I looked in `/tmp` but nothing like ‘*ecryptfs.123XYZ*’ is in there except *ssh-123XYZ* and *hsperfdata_NEW*.

This guys made it look easy on what to do with the file: http://hgoshawknest.wordpress.com/2010/04/16/how-to-recover-crypted-home-directory-in-ubuntu/

But again, this is not working for me.

CURRENT STEPS:
————–

I am setting up a boot USB with Ubuntu 14, in hopes to follow directions on mounting properly (as in described here: http://ubuntuforums.org/showthread.php?t=1810825), but I am not sure I am working correctly.

Thanks in advance! This is amazingly important to recover my old setup, regardless of damn username and home folder name.

Please help with this if you can.

All the best!!!!

PS – Here is a list of references that helped me screw up (I mean execute) the above:

RESOURCES:
———-

1. http://www.cyberciti.biz/faq/howto-change-rename-user-name-id/
2. http://jesin.tk/change-home-directory-in-linux/
3. http://www.ubuntututorials.com/change-username-ubuntu-12-04/
4. http://ubuntuforums.org/showthread.php?t=2103420
5. http://askubuntu.com/questions/34074/how-do-i-change-my-username
6. http://bodhizazen.net/Tutorials/Ecryptfs#Live
7. http://bugs.launchpad.net/ubuntu/+source/ecryptfs-utils/+bug/1028532
8. http://askubuntu.com/questions/190404/changed-username-now-i-cannot-log-on-or-view-my-previous-files
9. http://manpages.ubuntu.com/manpages/jaunty/man8/usermod.8.html

Reply

56 Keshav Agrawal August 25, 2014 at 3:42 am

Thanks!

Reply

Leave a Comment

Tagged as: , , , , ,

Previous Faq:

Next Faq: