# Auto-create home folders for Active Directory users on RHEL / Rocky

When Linux servers are joined to Active Directory (SSSD or winbind), domain users who log in for the first time have no `/home/<user>`.

## Recommended: use the built-in feature
RHEL, Rocky and Alma 8/9 ship this already:
```
sudo dnf install oddjob-mkhomedir
sudo authselect enable-feature with-mkhomedir
sudo systemctl enable --now oddjobd
```
The home folder is then created from `/etc/skel` at first login, with the right owner and SELinux context.

## Manual fallback (one user)
If you need to create a home folder by hand, quote everything. Group names like `domain users` contain a space.
```
#!/bin/bash
set -euo pipefail
u=${1:?usage: mkhome <user>}
id "$u" >/dev/null                      # make sure the user resolves
install -d -m 700 -o "$u" -g "domain users" "/home/$u"
cp -rT /etc/skel "/home/$u"
chown -R "$u":"domain users" "/home/$u"
restorecon -R "/home/$u"
```

## Gotcha
Copying commands from Word or email can turn `"` into curly "smart quotes". The shell treats them as part of the text, so `chown` gets a group name that doesn't exist. Retype the quotes if a command fails mysteriously.
