LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu
User Name
Password
Ubuntu This forum is for the discussion of Ubuntu Linux.

Notices


Reply
  Search this Thread
Old 03-16-2007, 02:57 PM   #1
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Rep: Reputation: 77
Useradd Help


I tried today to add a user to a machine using the following command:

Code:
sudo useradd -c Mike\ Smith msmith
Password:
cwilliams@tank:~$ cd /home/
cwilliams@tank:/home$ ls
cwilliams
When I su to msmith, there is still no home directory for him so he appears to be floating in limbo.

Can someone tell me what I did wrong and or what I need to do from here...
 
Old 03-16-2007, 03:03 PM   #2
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
To create users with useradd, I think the syntax should be something like
Code:
$sudo useradd -c "Mike Smith" msmith
Usually that creates the home directory as well. If for some reason your system is not creating home directories by default, try
Code:
$sudo useradd -c "Mike Smith" -m -d /home/msmith msmith
If the user you created is already listed in your /etc/passwd, then you could remedy the problem by creating the users home directory manually, copying the files from /etc/skel to the users home directory and then changing permissons for the users home directory so that they own it and have read, write and execute permissions.

Last edited by reddazz; 03-16-2007 at 03:06 PM.
 
Old 03-16-2007, 03:12 PM   #3
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
I just tired the following and still no luck...

Code:
root@tank:/home# whoami
root
root@tank:/home# pwd
/home
root@tank:/home# ls -la
total 12
drwxr-xr-x  3 root      root      4096 2007-03-15 19:48 .
drwxr-xr-x 21 root      root      4096 2007-03-15 19:49 ..
drwxr-xr-x 15 cwilliams cwilliams 4096 2007-03-16 15:06 cwilliams
root@tank:/home# finger lmcgrath
Login: lmcgrath                         Name: Laura Mcgrath
Directory: /home/lmcgrath               Shell: /bin/sh
Never logged in.
No mail.
No Plan.
root@tank:/home# usermod -d /home/lmcgrath lmcgrath
root@tank:/home# ls -la
total 12
drwxr-xr-x  3 root      root      4096 2007-03-15 19:48 .
drwxr-xr-x 21 root      root      4096 2007-03-15 19:49 ..
drwxr-xr-x 15 cwilliams cwilliams 4096 2007-03-16 15:06 cwilliams
 
Old 03-16-2007, 04:20 PM   #4
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Usermod does not change the ownership of the directory, you have to use chown (and chmod to change and permissions if you need to) e.g.
Code:
$chown -R lmcgrath:lmcgrath /home/lmcgrath
 
Old 03-16-2007, 05:25 PM   #5
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Quote:
Originally Posted by reddazz
Usermod does not change the ownership of the directory, you have to use chown (and chmod to change and permissions if you need to) e.g.
Code:
$chown -R lmcgrath:lmcgrath /home/lmcgrath
Yes - the problem is that my Linux system did not create this directory with the useradd command but it did create the user account (uid) and group (guid). Now I tried to usermod with the -d option to force it to create /home/lmcgrath directory but as you can see it still did no such thing.

Your suggestion of chown is confusing since you're telling Linux to own a directory that does not exist. The problem of /home/lmcgrath directory not existing needs to be resolved before we can start assessing ownership of it.
 
Old 03-16-2007, 06:24 PM   #6
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
If it does not exist, then the solution is simple really. Create the directory manually as root using mkdir, copy the files in /etc/skel (including the hidden ones) to the directory you created and then use chown as I described above to change ownership to the user. Another option would be to use userdel to delete the user and the use a command similar to the second one in my first post to recreate the user account.

Last edited by reddazz; 03-16-2007 at 06:31 PM.
 
Old 03-16-2007, 07:04 PM   #7
carlosinfl
Senior Member
 
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905

Original Poster
Rep: Reputation: 77
Yes - I removed the user but I am still in the dark as to why the "useradd" command does not auto create the proper directory and files / permissions for this user. I don't want to have to hack the directory every time I create a new user and copy over files and then chmod the thing when it should simply work as simple as "useradd bob" and then I should have a /home/bob where I can see everything I need with ls -la.
 
Old 03-16-2007, 09:10 PM   #8
reddazz
LQ Guru
 
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298

Rep: Reputation: 77
Did this issue happen on Debian? I have just tried adding a user on a Debian system and I had the same results as you. This article may help resolve your problem although I have not tried it.

Last edited by reddazz; 03-16-2007 at 09:12 PM.
 
Old 03-17-2007, 12:36 AM   #9
ORBiTrus
Member
 
Registered: Sep 2004
Location: On a compile thread
Distribution: CentOS, Debian, Fedora, Gentoo, Mandriva, Slackware, Ubuntu
Posts: 42

Rep: Reputation: 15
$ man useradd
-d, --home HOME_DIR
The new user will be created using HOME_DIR as the value for the
user's login directory. The default is to append the LOGIN name to
BASE_DIR and use that as the login directory name. The directory
HOME_DIR does not have to exist but will not be created if it is
missing.
-m, --create-home
The user's home directory will be created if it does not exist. The
files contained in SKEL_DIR will be copied to the home directory if
the -k option is used, otherwise the files contained in /etc/skel
will be used instead. Any directories contained in SKEL_DIR or
/etc/skel will be created in the user's home directory as well. The
-k option is only valid in conjunction with the -m option. The
default is to not create the directory and to not copy any files.

$ man usermod
-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.

--------

You took redazz's comment to run useradd (which would require running userdel first) and used the -m -k on usermod! But, as the manual clearly says, running usermod with the -m option simply tried to move a non-existant directory. Whereas using the -m option on useradd is what will create the directory.

Bit of a "doh!" moment, I suppose.
 
  


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
please tell me how to use useradd -b sabarigg Red Hat 2 06-08-2006 12:15 AM
useradd taizhu Red Hat 1 05-18-2006 12:01 PM
useradd -D doronunu Linux - Networking 10 01-19-2006 04:11 AM
Useradd - Cannot locate /etc/default/useradd in Solaris Paean Solaris / OpenSolaris 4 12-09-2005 02:36 AM
Using Useradd spud Linux - Newbie 6 03-10-2005 04:50 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Ubuntu

All times are GMT -5. The time now is 01:43 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
Open Source Consulting | Domain Registration