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 created a new user with useradd name and forgot to use -d -m to create their home directory. I tried making one, copying the contents of /etc/skel, and chowning everything to the new user.

Aliases don't work, such as ll, and I just have a $ at the command prompt, instead of name@server ~$. Also, using the scroll wheel dumps garbage on the command line :(

How do I fix this, or is it easier to delete the user and start over?

share|improve this question
    
I haven't figured out what else was needed from that point, but I fixed it by deleting the user and directory and starting over with adduser instead of useradd. –  mortona42 Jun 18 '12 at 19:50
    
I think that would result in a different userid and groupid which may or may not be a problem for you. –  Grant Bowman Aug 26 at 9:43

4 Answers 4

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.

share|improve this answer
    
My output from that last command was 'usermod: no changes' even though there's no directory in the home folder –  AlxVallejo May 8 at 12:45
    
@AlxVallejo , thanks for the comment. I did some testing and edited my answer accordingly. Hopefully it helps answer your question as well. –  iridescent Jun 20 at 14:54
    
@iridescent Thanks for your testing. The hint about the shell is helpful. I think your description of the two cases is almost complete but unintentionally misleads a bit by describing "the only way" at the end. Indeed, the home directory must be specified in /etc/passwd. This is independent of /home having a <username> directory on disk, preventing mkhomedir_helper from completing. A quick rm -rf /home/<username> should allow mkhomedir_helper <username> to complete the tasks manually performed by the @Zenexer script below. –  Grant Bowman Aug 26 at 10:19
    
sudo mkhomedir_helper <username> worked for me. mkhomedir_helper fails silently without sudo. –  mv288 Dec 8 at 10:10

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 
share|improve this answer
    
When I did echo $HOME after just using useradd, it gave me /home/new_user, so I don't think that was the problem, unless that wasn't a good indicator. –  mortona42 Jun 18 '12 at 21:04
2  
This answer is irrelevant to the question. I only say this because this command is for changing the default values on your system, and can cause damage if you use it expecting something else. –  Zenexer Jun 20 '13 at 7:33

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
share|improve this answer

I just ran into this (Ubuntu 12.04) and I solved it by creating a temp user, copying over the user directory, chowning it, and finally deleting the temp user.

sudo adduser temp
sudo cp -r /home/temp /home/name
sudo chown -R name.name /home/name
sudo deluser temp
share|improve this answer
    
How do I change the $HOME for "name"? –  Bryan Glazer Dec 2 '13 at 3:16

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.