Linux – create home directories after create users

linuxuser-management

I created some users with:

$ useradd john

and I forgot to specify the parameter -m to create the home directory and to have the skeleton files copied to each user. now I want to do that, and I don't want to recreate all users (there must be an easier way). so, is there any way to create the user directories and copy the skeleton files?

I thought about creating the directories, chowning them to the corresponding user, copying all the skeleton files and chowning them to the corresponding user. but if there's a command like useradd -m that doesn't create the user again, but create the directories, it'd be better.

Best Answer

This might sound like a silly idea, but if the users aren't actually doing anything, you could do:

cat /etc/passwd | cut -f 1 -d : >/tmp/users.list

Then edit /tmp/users.list to only contain the users you want. Then do:


for i in `cat /tmp/users.list`
do
    userdel $i
    useradd -m $i
done

However, many Redhat based distributions will create you a new home directory when you first login, providing it is specified in /etc/passwd where the directory should be.

To test that, do an "su - " and see if it does "the right thing". If it doesn't, the above script will work quite nicely, I think.