Home directory not being created
Solution 1
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.
Solution 2
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.
Solution 3
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?
Solution 4
Look at /etc/defaults/useradd
if you want to change the defaults. Use:
useradd -m -d /home/joe -s /bin/bash
.
Solution 5
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
Related videos on Youtube
tchakravarty
Updated on September 18, 2022Comments
-
tchakravarty over 1 year
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 usingcat /etc/passwd
linda:x:1004:1004::/home/linda:/bin/sh
However, when I
su - linda
, I getNo directory, logging in with HOME=/
and indeed, no home directory has been created. What am I missing?
Thanks.
-
Keith Bennett almost 9 yearsIn the OP's defense, when I read "On Debian,", I thought it meant on Debian as opposed to Ubuntu distros. I am aware that Ubuntu is built on Debian but thought that a distinction was being made.
-
mcExchange over 8 yearsI used
adduser
but still the created home directory only contains a fileexamples.desktop
and nothing else. How can I get Ubuntu to create the default folders Desktop, Downloads and so on? (I'm logged in via ssh) -
Admin about 8 yearsIt worked for me. I needed to have a basic script that will remotely add/manage users on different flavors of Linux. After this change my code produces same results on all servers. Thanks.
-
astrojuanlu over 6 years"According with man useradd, -d /home/linda option will not create the directory /home/linda" so no, this is not a solution.
-
derHugo over 6 yearsHi, sorry late response and only guessing but I think those folders are created automatically on the first GUI login. Just thought people might still land here ;)
-
Noumenon almost 6 years
adduser
will not create the directory either if someone has changed CREATE_HOME in /etc/login.defs to "no". You can override this with the-m
flag. -
Myles almost 5 yearsAccording to the useradd man page, that's what the -m flag is for:
-m, --create-home Create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory. useradd will create the home directory unless CREATE_HOME in /etc/login.defs is set to no.
@astrojuanlu -
Mike Q over 4 yearsThis is the correct answer.
-
Justin G over 3 yearsLife saver, only solution that worked for me. Was using os.system in python to call useradd btw, so it's likely related to that.
-
ali Falahati over 3 yearsthat was great thank you it solved my problem also
-
Trevor Boyd Smith over 3 yearsnote for rhel users: i think this question/solution also applies. on centos7 you have to yum install
shadow-utils
to getadduser
and then you can useadduser
.