LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-22-2011, 01:24 PM   #1
noony123
Member
 
Registered: Oct 2010
Posts: 167

Rep: Reputation: 0
usermod command not working properly !


Hi all.

I created a user named Bob. Now i want to change its home directory to be Bob1. I did this

usermod -d /home/Bob1 Bob

but not effect !!!

The name was still Bob. What might be issue ?

pls guide me

Last edited by noony123; 03-22-2011 at 01:25 PM.
 
Old 03-22-2011, 01:29 PM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380
Hi,

As which user did you execute that command and did Bob have any running jobs/instances?

From the manpage:
Quote:
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.
Hope this helps.
 
Old 03-22-2011, 01:31 PM   #3
szboardstretcher
Senior Member
 
Registered: Aug 2006
Location: Detroit, MI
Distribution: GNU/Linux systemd
Posts: 3,431
Blog Entries: 1

Rep: Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144Reputation: 1144
Code:
usermod --home /home/new/user/dir -m username
The user cannot be logged in or active.
 
Old 03-22-2011, 01:32 PM   #4
andrewthomas
Senior Member
 
Registered: May 2010
Location: Chicago Metro
Distribution: Arch, Gentoo, Slackware
Posts: 1,690

Rep: Reputation: 307Reputation: 307Reputation: 307Reputation: 307
Quote:
Originally Posted by noony123 View Post
Hi all.

I created a user named Bob. Now i want to change its home directory to be Bob1. I did this

usermod -d /home/Bob1 Bob

but not effect !!!

The name was still Bob. What might be issue ?

pls guide me
If you want to move the contents of Bob to Bob1 then you need the -m flag, furthermore if you want the login name to change you need the -l flag.
Code:
       -d, --home 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.


       -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.
 
Old 03-23-2011, 01:38 AM   #5
noony123
Member
 
Registered: Oct 2010
Posts: 167

Original Poster
Rep: Reputation: 0
Dear Fellows,

I was simply practicing the usermod command. I am logged in as root. I simply issued the following commands

1) useradd Bob
2) passwd Bob
3) ls /home ( to verify that /home/Bob exists )
4) usermod -d /home/Bob1 Bob

But no effect, i am not logged in as Bob. Any ideas pls ?

[Edit] I am using Centos 5.5. When i add the -m option, it doesnt execute, i am expecting that above usermod command will create a new dir in /home, is that right ?

Last edited by noony123; 03-23-2011 at 02:01 AM.
 
Old 03-23-2011, 02:48 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380Reputation: 2380
Hi,

The -m option moves the content from the old home directory into the new home directory.

useradd Bob - Maybe cent-os lets you do it the way you tried, but: useradd Bob will not work on most distro's (Bob is an illegal name, caps are not allowed. bob would be legal). It also does not create the home directory, you need to add the -m flag.

This would be correct: useradd -m -d /home/bob bob

The following would move all to the new home directory: usermod -d /home/bob -m bob (mind you: usermod -m -d /home/bob bob will not work).

Like I said before, maybe cent-os lets you create users that contain capitals, and also creates the homedir if you do not use the -m flag (talking about the useradd command). Not all distro's do.

Hope this helps.
 
Old 03-23-2011, 04:58 AM   #7
noony123
Member
 
Registered: Oct 2010
Posts: 167

Original Poster
Rep: Reputation: 0
Dear Sir,

I tried this

1) useradd jon
2) passwd jon

Now to modify the home directory of user jon using 'usermod' command

3) usermod -d /home/jon1 jon

No effect :-( i tried it with -m but no difference
 
Old 03-23-2011, 05:11 AM   #8
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,453

Rep: Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116Reputation: 2116
I tried your example on my Centos 5.5 box & it works, as specified by the manual
Quote:
-d, --home 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.
ie unless you specify the -m option, only the home dir as registered in /etc/passwd is changed.
This enables you to create a new home dir first if necessary, then switch the entry in/etc/passwd.
 
Old 03-23-2011, 06:16 AM   #9
noony123
Member
 
Registered: Oct 2010
Posts: 167

Original Poster
Rep: Reputation: 0
Dear Sir,

I was expecting that according to man page, new dir will be created automatically. I can see that entry in etc/passwd is changed but i wasnt seeing bob1 directory under /home. So you mean, my command executed but i need to create the new home dir manually ?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with usermod command pushpendra Linux - Desktop 3 05-27-2010 06:03 AM
ls -la command output is not working properly ratul_11 General 1 02-27-2008 12:38 PM
message command in smb.conf not working properly kamransoomro84 Linux - Desktop 0 11-07-2006 12:51 PM
Autostart command not working properly dstjames Linux - Newbie 2 01-10-2006 02:25 PM
command usermod not found bowie101 Linux - Newbie 5 11-25-2005 05:38 AM


All times are GMT -5. The time now is 12:15 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration