ML

mkhomedir

mkhomedir; V 1; 2010-01-20; creating users' home directories with customized permissions and ownership; SUID root safe

Synopsis and description

mkhomedir [--forcehome] [--overwrite] [--verbose] [ [--homedir=path] [--skel=path] [--uid=UID] [gid=GID] user ] ...

mkhomedir utility creates user's home directory from a predefined skeleton in a similar way to what useradd -m and pam_mkhomedir programs do. Additionaly, it retains file's permissions (without SxID bits) and ownership, if set. Therefore it is possible to create more advanced skeletons enabling, for example, WWW access to be set up automatically.

Downloading and compiling

Source code and manual pages: Requirements: Compiling and installing:
  • Edit defs.h first to customize the program
  • Run: make install

Examples

# ls -Al /etc/skel
-rw-r--r-- 1 root root 220 2006-12-11 21:20 .bash_logout
-rw-r--r-- 1 root root 3116 2008-05-12 19:02 .bashrc
-rw-r--r-- 1 root root 675 2008-05-12 19:02 .profile
drwxr-x--- 2 root www-data 48 2010-01-20 13:09 public_html
drwx------ 2 root root 48 2010-01-20 22:52 .ssh
# mkhomedir -Hv nobody
User "nobody" (uid=65534, gid=65534) with home "/home/nobody"
"/home/nobody" (65534.65534 0755)
"/home/nobody/.ssh" (65534.65534 0700)
"/home/nobody/.bashrc" (65534.65534 0644)
"/home/nobody/.bash_logout" (65534.65534 0644)
"/home/nobody/public_html" (65534.33 0750)
"/home/nobody/.profile" (65534.65534 0644)
# ls -Al /home/nobody
total 12
-rw-r--r-- 1 nobody nogroup 220 2010-01-20 22:53 .bash_logout
-rw-r--r-- 1 nobody nogroup 3116 2010-01-20 22:53 .bashrc
-rw-r--r-- 1 nobody nogroup 675 2010-01-20 22:53 .profile
drwxr-x--- 2 nobody www-data 48 2010-01-20 22:53 public_html
drwx------ 2 nobody nogroup 48 2010-01-20 22:53 .ssh