Home directory not being created

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 passwd to create 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.

11 Answers

man useradd states:

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

Note the low level utility

To add a user, use adduser instead. It's a more high-level utility.


Moreover, looking at the -d option:

 -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.

Generally, keep away from useradd, use adduser instead.

6

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.

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 -rT /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?

1

Look at /etc/defaults/useradd if you want to change the defaults. Use:

useradd -m -d /home/joe -s /bin/bash.

2

Use -m instead of -d, so the directory will be created for you:

sudo useradd -m linda

Also, if linda is a normal user, you might want her to use /bin/bash as default shell:

sudo useradd -m linda -s /bin/bash

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.

0

Add the below entry in /etc/login.defs and save:

CREATE_HOME yes

Now, try to create user accounts. It will create the home directory.

2

The most likely reason why you did not have the home directory created is because you did not have the CREATE_HOME yes in /etc/login.defs.

You can fix this by following what @OmPS or @Radu Rădeanu had suggested.

But that many ways to overcome this problem in future by using one of the commands below:

  • Result of sudo adduser linda

    Adding user 'linda'
    Adding new group 'linda' (1001) ...
    Adding new user 'linda' (1001) with group 'linda' ...
    Creating home directory '/home/linda' ...
    Copying files from '/etc/skel' ...
    ****Password confirmation****
    ****Name prompt****

    The defaults for adduser are chosen from /etc/adduser.conf if--home option is not specified.Note that it also copies the /etc/skel contents.

  • Use adduser with --home

    sudo adduser --home /home/linda

Same as previous option except that you may want this if the users home directory is different than the username that you assigned.

  • Specify base directory to useradd command:

    sudo useradd -b /home
  • Use login.defs: Modify /etc/login.defs and add the line below before doing sudo useradd:

    CREATE_HOME yes

Note: if you do man login.defs, it currently says

Much of the functionality that used to be provided by the shadow password suite is now handled by PAM. Thus, /etc/login.defs is no longer used by passwd(1), or less used by login(1), and su(1). Please refer to the corresponding PAM configuration files instead.

  • Use pam_mkhomedir PAM module: from man pam_mkhomedir page, add the line below to /etc/pam.d/login:

    session required pam_mkhomedir.so skel=/etc/skel

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!

If /home/linda is not present before you add linda as a user, you also would have to add --create-home.

sudo useradd --create-home linda

useradd command doesn't create a home directory automatically, regardless of the default settings in /etc/login. You have to specify the -m option if you want a home directory for a system account to be created.

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like