Ubuntu This forum is for the discussion of Ubuntu Linux. |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
03-16-2007, 02:57 PM
|
#1
|
Senior Member
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905
Rep:
|
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...
|
|
|
03-16-2007, 03:03 PM
|
#2
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
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.
|
|
|
03-16-2007, 03:12 PM
|
#3
|
Senior Member
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905
Original Poster
Rep:
|
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
|
|
|
03-16-2007, 04:20 PM
|
#4
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
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
|
|
|
03-16-2007, 05:25 PM
|
#5
|
Senior Member
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905
Original Poster
Rep:
|
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.
|
|
|
03-16-2007, 06:24 PM
|
#6
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
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.
|
|
|
03-16-2007, 07:04 PM
|
#7
|
Senior Member
Registered: May 2004
Location: Orlando, FL
Distribution: Arch
Posts: 2,905
Original Poster
Rep:
|
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.
|
|
|
03-16-2007, 09:10 PM
|
#8
|
LQ Guru
Registered: Nov 2003
Location: N. E. England
Distribution: Fedora, CentOS, Debian
Posts: 16,298
Rep:
|
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.
|
|
|
03-17-2007, 12:36 AM
|
#9
|
Member
Registered: Sep 2004
Location: On a compile thread
Distribution: CentOS, Debian, Fedora, Gentoo, Mandriva, Slackware, Ubuntu
Posts: 42
Rep:
|
$ 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.
|
|
|
All times are GMT -5. The time now is 01:43 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|