create home directories after create users

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.


Also you can use mkhomedir_helper

Usage: /sbin/mkhomedir_helper <username> [<umask> [<skeldir>]]

You will need to create the users directory manually. This requires three steps:

  1. Create directory in compliance to /etc/passwd, usually there will be already a /home/login entry.
  2. Copy initial files from /etc/skel
  3. And finally set right permissions:

    • mkdir /home/YOU
    • cd /home/YOU
    • cp -r /etc/skel/. .
    • chown -R YOU.YOURGROUP .
    • chmod -R go=u,go-w .
    • chmod go= .

BTW: I always miss the -m option for useradd too. At least Debian based systems should have an adduser command, which I recommend over useradd. If you missed -m option it might also be worth considering to deluser and then recreate the user with proper options.

Edit: Added -r for copying also directories.