creating user dirs

Karl Vogel vogelke at pobox.com
Fri Sep 24 08:51:38 PDT 2004


>> On Tue, 7 Jan 2003 13:44:53 +0200, 
>> Lauri Laupmaa <mauri at minut.ee> said:

L> Is there a simple solution for creating all user directories under
L> /home?  So, I have clean /home filesystem and hundreds of users in
L> /etc/*passwd. Hopefully there is some simple command or script :)

   Create a subset of the passwd file with the user, group, and home
   directory only:

     # cut -f1,4,6 -d: /etc/passwd | grep /home/ | sed -e 's/:/ /g' > /tmp/pw

   Create the directory tree.  You need the '-p' flag in mkdir if you
   have multiple levels of directories under /home:

     # awk '{print "mkdir -p", $3}' /tmp/pw | sh

   Next, set permissions.  Use 750 instead of 755 if you don't want
   world read access to user's home directories:

     # awk '{print "chmod 755", $3}' /tmp/pw | sh

   If you want to populate the home directories with some default dot files
   (.profile, etc) you can do something like

     # cd /etc/skel
     # awk '{print "find . -print | cpio -pdum", $3}' /tmp/pw 

   Finally, set ownerships.  This assumes you want the user's home
   directory and files owned by the user and the default user's group:

     # awk '{print "chown -R", $1"."$2, $3}' /tmp/pw | sh
     # rm /tmp/pw

-- 
Karl Vogel                      I don't speak for the USAF or my company
vogelke at pobox.com                          http://www.pobox.com/~vogelke

If all the veins in your body were laid end to end, you'd be dead.
                                                --unknown

To Unsubscribe: send mail to majordomo at FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



More information about the freebsd-questions mailing list