Click to See Complete Forum and Search --> : usermod


Ops
10-06-2003, 12:09 PM
i would like to change my name but I dont quite make out the command to change the name of the user directory using usermod

Is there a command that completely changes the username and home directory?

I am using RH 9

Hayl
10-06-2003, 12:23 PM
not that i am aware of. just use teh mv command to rename the user's home dir.

i.e.


mv /home/foo /home/bar

camelrider
10-06-2003, 03:52 PM
-d home_dir
The user's new login directory. If the -m option is given the
contents of the current home directory will be moved to the new
home directory, which is created if it does not already exist.

also:
CAVEATS
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.

Man pages are your friend. :)

Ops
10-07-2003, 07:54 PM
[root@localhost ops]# usermod
bash: usermod: command not found
[root@localhost ops]# whereis usermod
usermod: /usr/sbin/usermod /usr/share/man/man8/usermod.8.gz
[root@localhost ops]#

How can i make usermod to work?

I also have trouble with useradd


[root@localhost ops]# useradd
bash: useradd: command not found
[root@localhost ops]# whereis useradd
useradd: /usr/sbin/useradd /usr/share/man/man8/useradd.8.gz
[root@localhost ops]#

serz
10-07-2003, 08:09 PM
Are you using su? If so, you have to use su - instead of just su, so it dosn't use your current $PATH environment.

Sepero
10-08-2003, 07:01 AM
To serz:

May I recommend that you make use of quotations, they help define exactly where you begin and end. "su -"
(btw: I have always used "su" and never needed the use of "su -". Perhaps because I am using debian?)

To Ops:
Some distros will install the man pages for a program and not the program itself. Make sure that the program IS indeed installed.
find /[!m,d,p]* -name "usermod"

serz
10-08-2003, 07:21 AM
I appreciate your suggestion, Sepero. It's just that the "-" is not noticeable when it's bold :(

Maybe debian has an alias for su?

Alex Cavnar, aka alc6379
10-09-2003, 02:08 AM
You can't use usermod to edit your username. The only way to do that is to actually get in and edit /etc/passwd and /etc/shadow. You'll be doing all of this as the root user, not in su. Actually log out of the regular user account and log in as root, preferably in text mode, not in a GUI.

For this, you'll need a text editor. I prefer vim, but you can use whatever you're comfortable with. First, open up /etc/password, and locate the listing for the user you want to edit. In this example, the user will be named joeuser:

joeuser:x:1000:1000:Joe User:/home/joeuser:/bin/bash

Now, you edit the fields pertaining to your changes. In our case, we want to fool with the username and the directory. I'll underline those fields for clarity. Just change the username to whatever you want, and change the home directory to the new one:

billyboy:x:1000:1000:Joe User:/home/billyboy:/bin/bash

Save your changes, and then open up /etc/shadow. Locate the old user's name. Again, I underlined it:

joeuser:$1$R/2.FWWU$WMRfewabcdefUlKn/1VE30:11977:0:99999:7:::

..and change the name on that:

billyboy:$1$R/2.FWWU$WMRfewabcdefUlKn/1VE30:11977:0:99999:7:::

Now, you've changed the name, and the location of the home dir. Now, all you have to do is edit the group memberships. Open up /etc/group in the text editor, and find any line that has the old user's name at the end of it, or somewhere after the third colon (the : symbol :)), and change the name to the new one. Now, your new username has all of the group memberships your old one had.

If you want to keep your files, all that's left to do is move the home directory to its new name. As root, you just move it:

mv /home/joeuser /home/billyboy

You don't need to change any permissions because the UID is already mapped to the new username. Nifty, eh? Feel free to post any questions you may have. I'm sure someone could probably write a script to automate all of this, but I for one don't have the time to!