How to make user home folder after account creation? [duplicate]

You have $ at the command prompt because you are using the sh shell.

The shell with name@server is based on the bash shell.

You have to change the default shell for the newly created user via : usermod -s /bin/bash .

Using usermod again to add the user home directory if it wasn't present. usermod -d /home/username

If the user has no home directory specified in /etc/passwd :

Run mkhomedir_helper <username> to create the home directory. mkhomedir_helper will create the user home directory and copy the stuff in /etc/skel as well.

If the user already has a home directory specified in /etc/passwd :

Such as via usermod -d /some/directory , mkhomedir_helper will not work. The only way is to manually create the home directory for the affected user.


If you forgot to use -d -m, the best and quick option is to run

sudo mkhomedir_helper username

with creates the home directory as if you would have provided the missing options.


Here's a quick bash script. Run as root with sudo. It takes any number of arguments, each being a username in need of a home directory. This makes a few assumptions: that your home directories are in /home, and that your skeleton directory is /etc/skel. These are the defaults on Ubuntu. You can download or wget/curl this script from gist.

#!/bin/bash
if [ $# -lt 1 ]; then
    echo "Syntax: $_ USER[ USER[ ...]]" >&2
    exit 1
fi

exit_code=0

for user in "$@"; do
    home="/home/$user"
    cp -R /etc/skel "$home" && echo $'\e[32m'"Copied skeleton to: $home"$'\e[m' || ( exit_code=$?; echo $'\e[31m'"Failed to create: $home"$'\e[m' ) >&2
    chown -R "$user:$user" "$home" && echo $'\e[32m'"Set owner on: $home"$'\e[m' || ( exit_code=$?; echo $'\e[31m'"Failed to set owner on: $home"$'\e[m' ) >&2
done

exit $exit_code

To change the default value of the new user's home directory, you can give

sudo useradd -D --base-dir /home/new_user

command. See useradd -D [options] from

man useradd