Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I am trying to understand system administration on Ubuntu. So, as an example, I create a dummy user using

sudo useradd -d /home/linda linda

and the passwd to create a the password. I check that an entry has been made using cat /etc/passwd

linda:x:1004:1004::/home/linda:/bin/sh

However, when I su - linda, I get

No directory, logging in with HOME=/

and indeed, no home directory has been created. What am I missing?

Thanks.

share|improve this question
add comment

5 Answers

up vote 7 down vote accepted

If you only had read man useradd you would have seen:

useradd is a low level utility for adding users. On Debian,
administrators should usually use adduser(8) instead.

low level utility!!!

To add a user, use adduser instead.


Moreover, if you read carefully what the -d option does (still in 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.

The directory will not be created if it is missing.

Definitely, keep away from useradd, use adduser instead.

share|improve this answer
add comment

you can fix this simply by creating the home dir.

mkdir /home/linda
chown linda:linda /home/linda

try logging in again and this should work.

share|improve this answer
add comment

According with man useradd, -d /home/linda option will not create the directory /home/linda, if this is missing. So, you have to create it manually. To do this, run the followings commands in terminal:

sudo -i                            #to get root privileges
mkdir /home/linda                  #to create the directory /home/linda
cp /etc/skel/* /home/linda         #to populate /home/linda with default files and folders
chown -R linda:linda /home/linda   #to change the owner of /home/linda to user linda

See also: How to make user home folder after account creation?

share|improve this answer
    
+1 for mentioning /etc/skel –  Joe Nov 14 '13 at 2:11
add comment

Use adduser.

DESCRIPTION

 adduser  and  addgroup  add users and groups to the system according to
   command    line    options    and    configuration    information    in
   /etc/adduser.conf.   They  are  friendlier  front ends to the low level
   tools like useradd, groupadd and usermod programs, by default  choosing
   Debian  policy conformant UID and GID values, creating a home directory
   with skeletal configuration, running a custom script,  and  other  fea‐
   tures.  adduser and addgroup can be run in one of five modes:

useradd you have to add all options yourself. Including permissions and some other things.adduser does this based on sane defaults (and also adds home dir by itself).

If you need to use adduser you probably need the -b option together with the -d option!

share|improve this answer
add comment

You can also modify /etc/pam.d/common-session to make it so that a user's home directory will be created on first log in. Add the following line to that file.

...
session required pam_mkhomedir.so

This is particularly useful if your system is on a network where the users are managed externally to your machine, by LDAP for instance.

share|improve this answer
    
Good advice, thanks. –  fg nu Nov 13 '13 at 22:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.