You are not logged in.

#1 2009-01-26 19:12:55

tjwoosta
Member
Registered: 2008-12-18
Posts: 453

how to change the name of an existing user?

i found this command on this other website but i have been hesitant to try it because im araid it might screw everything up

usermod -l login-name old-name

http://www.cyberciti.biz/faq/howto-chan … r-name-id/

now my understanding is that i would also need to manually rename the home directory, but my question is what else will i need to do

so far all i can think of that i might need to change is home directory and sudoers file

i have searched abit on google for info about changing a users name but there seems to be a slight lack of documentation available on this subject

before i dive into this and possibly screw something up, does anybody here have any experience with changing users names?

if so what other problems might i run into?

do i need to change my uid also or can i keep the existing one?

Offline

#2 2009-01-26 19:18:57

weasel8
Member
Registered: 2008-12-15
Posts: 149

Re: how to change the name of an existing user?

man usermod
       -l, --login NEW_LOGIN
           The name of the user will be changed from LOGIN to NEW_LOGIN.
           Nothing else is changed. In particular, the user's home directory
           name should probably be changed manually to reflect the new login
           name.

Offline

#3 2009-01-26 19:24:40

kludge
Member
Registered: 2008-08-03
Posts: 294

Re: how to change the name of an existing user?

'usermod', hunh?  that's cool.  i've done it by hand before, and all i *remember* changing were the entries in /etc/{passwd,group,sudoers,et al.}.  the usermod man page has a *caveats* section you'll want to read.  also, just to make sure you get everything, you might want to run 'grep -R username /' after the name change to find any files where the username has been hardcoded.  but afaik, the uid is more important than the username for the base system, so definitely leave that in place.

good luck, and please report success or failure!


[23:00:16]    dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32]    dr_kludge | can you guess what i'd call it?
[23:01:16]    dr_kludge | nosilla.
[23:01:32]    dr_kludge | i really should be going to bed.  i'm giggling madly about that.

Offline

#4 2009-01-26 19:31:51

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: how to change the name of an existing user?

Besides renaming $HOME,

chown Newyou:users $(find / -user Oldyou)

(I wonder if that would hit any limit to number of arguments or something? Maybe you should start with chown -R Newyou:users /home/Newyou, and then run it.

Anything that has paths in the file. grep -R Newyou / for an indication
Any binaries you built in your home dir with absolute paths might be affected (such as those that use a share directory.)

Offline

#5 2009-01-26 19:39:46

kludge
Member
Registered: 2008-08-03
Posts: 294

Re: how to change the name of an existing user?

Procyon wrote:
chown Newyou:users $(find / -user Oldyou)

(I wonder if that would hit any limit to number of arguments or something? Maybe you should start with chown -R Newyou:users /home/Newyou, and then run it.

i'm not sure about this.  if the new user has the same uid as the old, this should be unneccessary, as ownership is determined by uid, not uname.  the uname is mapped to the uid in /etc/passwd and the shadow files.


[23:00:16]    dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32]    dr_kludge | can you guess what i'd call it?
[23:01:16]    dr_kludge | nosilla.
[23:01:32]    dr_kludge | i really should be going to bed.  i'm giggling madly about that.

Offline

#6 2009-01-26 19:44:05

Procyon
Member
Registered: 2008-05-07
Posts: 1,819

Re: how to change the name of an existing user?

kludge wrote:
Procyon wrote:
chown Newyou:users $(find / -user Oldyou)

(I wonder if that would hit any limit to number of arguments or something? Maybe you should start with chown -R Newyou:users /home/Newyou, and then run it.

i'm not sure about this.  if the new user has the same uid as the old, this should be unneccessary, as ownership is determined by uid, not uname.  the uname is mapped to the uid in /etc/passwd and the shadow files.

I see. Does that mean if you change /etc/passwd and e.g. add a number after your name, it will show up the next time you ls -l?

Offline

#7 2009-01-26 20:36:50

kludge
Member
Registered: 2008-08-03
Posts: 294

Re: how to change the name of an existing user?

Procyon wrote:
kludge wrote:
Procyon wrote:
chown Newyou:users $(find / -user Oldyou)

(I wonder if that would hit any limit to number of arguments or something? Maybe you should start with chown -R Newyou:users /home/Newyou, and then run it.

i'm not sure about this.  if the new user has the same uid as the old, this should be unneccessary, as ownership is determined by uid, not uname.  the uname is mapped to the uid in /etc/passwd and the shadow files.

I see. Does that mean if you change /etc/passwd and e.g. add a number after your name, it will show up the next time you ls -l?

i didn't add a uid in /etc/passwd, i just changed the old uname to the new uname and left everything else the same.  but yeah, after logging out and logging back in under the new uname (i might have had to reboot/rerun init... this was a long time ago), it showed up when i did ls -l.

i remember this because i remember being surprised by it.


[23:00:16]    dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32]    dr_kludge | can you guess what i'd call it?
[23:01:16]    dr_kludge | nosilla.
[23:01:32]    dr_kludge | i really should be going to bed.  i'm giggling madly about that.

Offline

#8 2009-01-26 21:15:30

tjwoosta
Member
Registered: 2008-12-18
Posts: 453

Re: how to change the name of an existing user?

problem # 1

the user that i am changing is currently named arch and i want to name it to awesome (i am making seperate users for different WM's)

so i loged in as tj because

usermod will not allow you to change the name of a user who is logged
       in. You must make certain that the named user is not executing any
       processes when this command is being executed if the user's numerical
       user ID is being changed. You must change the owner of any crontab
       files manually. You must change the owner of any at jobs manually. You
       must make any changes involving NIS on the NIS server.

i did

su -

(to become root)

i ran the command and changed the users name

usermod -l awesome arch

i then became awesome to test that it worked

su awesome

it worked so i exited back to tj

exit

i became root again

su -

i renamed /home/arch to /home/awesome

cd /home
mv arch awesome

it all seemed to work

i became awesome again

su awesome

i noticed that i get 

bash-3.2$

instead of

[awesome@myhost ~]$

if i do cd ~ it says

bash: cd: /home/arch: No such file or directory

so basically my question now is..

what file do i need to edit to change the location of the home directory that the user is using?

Offline

#9 2009-01-26 21:24:33

kludge
Member
Registered: 2008-08-03
Posts: 294

Re: how to change the name of an existing user?

tjwoosta wrote:

if i do cd ~ it says

bash: cd: /home/arch: No such file or directory

so basically my question now is..

what file do i need to edit to change the location of the home directory that the user is using?

each user's home directory path is defined in one of the fields in that user's line in /etc/passwd.  'man 5 passwd' for the details.

Last edited by kludge (2009-01-26 21:26:02)


[23:00:16]    dr_kludge | i want to invent an olfactory human-computer interface, integrate it into the web standards, then produce my own forked browser.
[23:00:32]    dr_kludge | can you guess what i'd call it?
[23:01:16]    dr_kludge | nosilla.
[23:01:32]    dr_kludge | i really should be going to bed.  i'm giggling madly about that.

Offline

#10 2009-01-26 21:28:11

jacko
Member
Registered: 2007-11-23
Posts: 840

Re: how to change the name of an existing user?

I don't know how everyone else has ever done this, but I just logged in as root, deleted my old login, switched ownerships of all files and changed name of the ~/ dir to new user login and then recreated the user specifying the ~/ directory (of the old user with the new name) upon creation of the newuser.

I didn't have any trouble with this method. But you are using root so it can be dangerous I suppose.

Last edited by jacko (2009-01-26 21:39:19)

Offline

#11 2009-01-26 21:43:48

tjwoosta
Member
Registered: 2008-12-18
Posts: 453

Re: how to change the name of an existing user?

each user's home directory path is defined in one of the fields in that user's line in /etc/passwd.  'man 5 passwd' for the details.

thanks, it works

all seems to be working as normal now

thank you all for your help

Offline

Board footer

Powered by FluxBB